Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 65 additions & 7 deletions datafusion/core/tests/fuzz_cases/record_batch_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ use std::sync::Arc;

use arrow::array::{ArrayRef, RecordBatch};
use arrow::datatypes::{
BooleanType, DataType, Date32Type, Date64Type, Decimal128Type, Decimal256Type, Field,
Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type,
IntervalDayTimeType, IntervalMonthDayNanoType, IntervalUnit, IntervalYearMonthType,
Schema, Time32MillisecondType, Time32SecondType, Time64MicrosecondType,
Time64NanosecondType, TimeUnit, TimestampMicrosecondType, TimestampMillisecondType,
TimestampNanosecondType, TimestampSecondType, UInt16Type, UInt32Type, UInt64Type,
UInt8Type,
BooleanType, DataType, Date32Type, Date64Type, Decimal128Type, Decimal256Type,
DurationMicrosecondType, DurationMillisecondType, DurationNanosecondType,
DurationSecondType, Field, Float32Type, Float64Type, Int16Type, Int32Type, Int64Type,
Int8Type, IntervalDayTimeType, IntervalMonthDayNanoType, IntervalUnit,
IntervalYearMonthType, Schema, Time32MillisecondType, Time32SecondType,
Time64MicrosecondType, Time64NanosecondType, TimeUnit, TimestampMicrosecondType,
TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType, UInt16Type,
UInt32Type, UInt64Type, UInt8Type,
};
use arrow_schema::{
DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE, DECIMAL256_MAX_PRECISION,
Expand Down Expand Up @@ -85,6 +86,23 @@ pub fn get_supported_types_columns(rng_seed: u64) -> Vec<ColumnDescr> {
"interval_month_day_nano",
DataType::Interval(IntervalUnit::MonthDayNano),
),
// Internal error: AggregationFuzzer task error: JoinError::Panic(Id(29108), "called `Option::unwrap()` on a `None` value", ...).
// ColumnDescr::new(
// "duration_seconds",
// DataType::Duration(TimeUnit::Second),
// ),
ColumnDescr::new(
"duration_milliseconds",
DataType::Duration(TimeUnit::Millisecond),
),
ColumnDescr::new(
"duration_microsecond",
DataType::Duration(TimeUnit::Microsecond),
),
ColumnDescr::new(
"duration_nanosecond",
DataType::Duration(TimeUnit::Nanosecond),
),
ColumnDescr::new("decimal128", {
let precision: u8 = rng.gen_range(1..=DECIMAL128_MAX_PRECISION);
let scale: i8 = rng.gen_range(
Expand Down Expand Up @@ -484,6 +502,46 @@ impl RecordBatchGenerator {
IntervalMonthDayNanoType
)
}
DataType::Duration(TimeUnit::Second) => {
generate_primitive_array!(
self,
num_rows,
max_num_distinct,
batch_gen_rng,
array_gen_rng,
DurationSecondType
)
}
DataType::Duration(TimeUnit::Millisecond) => {
generate_primitive_array!(
self,
num_rows,
max_num_distinct,
batch_gen_rng,
array_gen_rng,
DurationMillisecondType
)
}
DataType::Duration(TimeUnit::Microsecond) => {
generate_primitive_array!(
self,
num_rows,
max_num_distinct,
batch_gen_rng,
array_gen_rng,
DurationMicrosecondType
)
}
DataType::Duration(TimeUnit::Nanosecond) => {
generate_primitive_array!(
self,
num_rows,
max_num_distinct,
batch_gen_rng,
array_gen_rng,
DurationNanosecondType
)
}
DataType::Timestamp(TimeUnit::Second, None) => {
generate_primitive_array!(
self,
Expand Down
1 change: 1 addition & 0 deletions test-utils/src/array_gen/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl PrimitiveArrayGenerator {
| DataType::Time32(_)
| DataType::Time64(_)
| DataType::Interval(_)
| DataType::Duration(_)
| DataType::Binary
| DataType::LargeBinary
| DataType::BinaryView
Expand Down
29 changes: 22 additions & 7 deletions test-utils/src/array_gen/random_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

use arrow::array::ArrowPrimitiveType;
use arrow::datatypes::{
i256, Date32Type, Date64Type, Decimal128Type, Decimal256Type, Float32Type,
Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, IntervalDayTime,
IntervalDayTimeType, IntervalMonthDayNano, IntervalMonthDayNanoType,
IntervalYearMonthType, Time32MillisecondType, Time32SecondType,
Time64MicrosecondType, Time64NanosecondType, TimestampMicrosecondType,
TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType, UInt16Type,
UInt32Type, UInt64Type, UInt8Type,
i256, Date32Type, Date64Type, Decimal128Type, Decimal256Type,
DurationMicrosecondType, DurationMillisecondType, DurationNanosecondType,
DurationSecondType, Float32Type, Float64Type, Int16Type, Int32Type, Int64Type,
Int8Type, IntervalDayTime, IntervalDayTimeType, IntervalMonthDayNano,
IntervalMonthDayNanoType, IntervalYearMonthType, Time32MillisecondType,
Time32SecondType, Time64MicrosecondType, Time64NanosecondType,
TimestampMicrosecondType, TimestampMillisecondType, TimestampNanosecondType,
TimestampSecondType, UInt16Type, UInt32Type, UInt64Type, UInt8Type,
};
use rand::distributions::Standard;
use rand::prelude::Distribution;
Expand Down Expand Up @@ -71,6 +72,11 @@ basic_random_data!(TimestampSecondType);
basic_random_data!(TimestampMillisecondType);
basic_random_data!(TimestampMicrosecondType);
basic_random_data!(TimestampNanosecondType);
// Note DurationSecondType is restricted to i64::MIN / 1000 to i64::MAX / 1000
// due to https://github.com/apache/arrow-rs/issues/7533 so handle it specially below
basic_random_data!(DurationMillisecondType);
basic_random_data!(DurationMicrosecondType);
basic_random_data!(DurationNanosecondType);

impl RandomNativeData for Date64Type {
fn generate_random_native_data(rng: &mut StdRng) -> Self::Native {
Expand Down Expand Up @@ -100,6 +106,15 @@ impl RandomNativeData for IntervalMonthDayNanoType {
}
}

// Restrict Duration(Seconds) to i64::MIN / 1000 to i64::MAX / 1000 to
// avoid panics on pretty printing. See
// https://github.com/apache/arrow-rs/issues/7533
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good doc for it, thanks @alamb .

impl RandomNativeData for DurationSecondType {
fn generate_random_native_data(rng: &mut StdRng) -> Self::Native {
rng.gen::<i64>() / 1000
}
}

impl RandomNativeData for Decimal256Type {
fn generate_random_native_data(rng: &mut StdRng) -> Self::Native {
i256::from_parts(rng.gen::<u128>(), rng.gen::<i128>())
Expand Down
Loading