risingwave_common/test_utils/
rand_chunk.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::array::{
16    BoolArray, DataChunk, DateArray, DecimalArray, F32Array, F64Array, I16Array, I32Array,
17    I64Array, Int256Array, IntervalArray, SerialArray, TimeArray, TimestampArray, TimestamptzArray,
18    Utf8Array,
19};
20use crate::test_utils::rand_array::seed_rand_array_ref;
21use crate::types::DataType;
22use crate::util::schema_check;
23
24pub fn gen_chunk(data_types: &[DataType], size: usize, seed: u64, null_ratio: f64) -> DataChunk {
25    let mut columns = vec![];
26
27    for d in data_types {
28        columns.push(match d {
29            DataType::Boolean => seed_rand_array_ref::<BoolArray>(size, seed, null_ratio),
30            DataType::Int16 => seed_rand_array_ref::<I16Array>(size, seed, null_ratio),
31            DataType::Int32 => seed_rand_array_ref::<I32Array>(size, seed, null_ratio),
32            DataType::Int64 => seed_rand_array_ref::<I64Array>(size, seed, null_ratio),
33            DataType::Float32 => seed_rand_array_ref::<F32Array>(size, seed, null_ratio),
34            DataType::Float64 => seed_rand_array_ref::<F64Array>(size, seed, null_ratio),
35            DataType::Decimal => seed_rand_array_ref::<DecimalArray>(size, seed, null_ratio),
36            DataType::Date => seed_rand_array_ref::<DateArray>(size, seed, null_ratio),
37            DataType::Varchar => seed_rand_array_ref::<Utf8Array>(size, seed, null_ratio),
38            DataType::Time => seed_rand_array_ref::<TimeArray>(size, seed, null_ratio),
39            DataType::Serial => seed_rand_array_ref::<SerialArray>(size, seed, null_ratio),
40            DataType::Timestamp => seed_rand_array_ref::<TimestampArray>(size, seed, null_ratio),
41            DataType::Timestamptz => {
42                seed_rand_array_ref::<TimestamptzArray>(size, seed, null_ratio)
43            }
44            DataType::Interval => seed_rand_array_ref::<IntervalArray>(size, seed, null_ratio),
45            DataType::Int256 => seed_rand_array_ref::<Int256Array>(size, seed, null_ratio),
46            DataType::Struct(_)
47            | DataType::Bytea
48            | DataType::Jsonb
49            | DataType::List(_)
50            | DataType::Map(_) => {
51                todo!()
52            }
53        });
54    }
55    schema_check::schema_check(data_types, &columns).unwrap();
56    DataChunk::new(columns, size)
57}