Skip to content

Commit febc77e

Browse files
authored
Test Duration in fuzz tests (#16111)
1 parent 52f340b commit febc77e

File tree

3 files changed

+88
-14
lines changed

3 files changed

+88
-14
lines changed

datafusion/core/tests/fuzz_cases/record_batch_generator.rs

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ use std::sync::Arc;
1919

2020
use arrow::array::{ArrayRef, RecordBatch};
2121
use arrow::datatypes::{
22-
BooleanType, DataType, Date32Type, Date64Type, Decimal128Type, Decimal256Type, Field,
23-
Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type,
24-
IntervalDayTimeType, IntervalMonthDayNanoType, IntervalUnit, IntervalYearMonthType,
25-
Schema, Time32MillisecondType, Time32SecondType, Time64MicrosecondType,
26-
Time64NanosecondType, TimeUnit, TimestampMicrosecondType, TimestampMillisecondType,
27-
TimestampNanosecondType, TimestampSecondType, UInt16Type, UInt32Type, UInt64Type,
28-
UInt8Type,
22+
BooleanType, DataType, Date32Type, Date64Type, Decimal128Type, Decimal256Type,
23+
DurationMicrosecondType, DurationMillisecondType, DurationNanosecondType,
24+
DurationSecondType, Field, Float32Type, Float64Type, Int16Type, Int32Type, Int64Type,
25+
Int8Type, IntervalDayTimeType, IntervalMonthDayNanoType, IntervalUnit,
26+
IntervalYearMonthType, Schema, Time32MillisecondType, Time32SecondType,
27+
Time64MicrosecondType, Time64NanosecondType, TimeUnit, TimestampMicrosecondType,
28+
TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType, UInt16Type,
29+
UInt32Type, UInt64Type, UInt8Type,
2930
};
3031
use arrow_schema::{
3132
DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE, DECIMAL256_MAX_PRECISION,
@@ -85,6 +86,23 @@ pub fn get_supported_types_columns(rng_seed: u64) -> Vec<ColumnDescr> {
8586
"interval_month_day_nano",
8687
DataType::Interval(IntervalUnit::MonthDayNano),
8788
),
89+
// Internal error: AggregationFuzzer task error: JoinError::Panic(Id(29108), "called `Option::unwrap()` on a `None` value", ...).
90+
// ColumnDescr::new(
91+
// "duration_seconds",
92+
// DataType::Duration(TimeUnit::Second),
93+
// ),
94+
ColumnDescr::new(
95+
"duration_milliseconds",
96+
DataType::Duration(TimeUnit::Millisecond),
97+
),
98+
ColumnDescr::new(
99+
"duration_microsecond",
100+
DataType::Duration(TimeUnit::Microsecond),
101+
),
102+
ColumnDescr::new(
103+
"duration_nanosecond",
104+
DataType::Duration(TimeUnit::Nanosecond),
105+
),
88106
ColumnDescr::new("decimal128", {
89107
let precision: u8 = rng.gen_range(1..=DECIMAL128_MAX_PRECISION);
90108
let scale: i8 = rng.gen_range(
@@ -484,6 +502,46 @@ impl RecordBatchGenerator {
484502
IntervalMonthDayNanoType
485503
)
486504
}
505+
DataType::Duration(TimeUnit::Second) => {
506+
generate_primitive_array!(
507+
self,
508+
num_rows,
509+
max_num_distinct,
510+
batch_gen_rng,
511+
array_gen_rng,
512+
DurationSecondType
513+
)
514+
}
515+
DataType::Duration(TimeUnit::Millisecond) => {
516+
generate_primitive_array!(
517+
self,
518+
num_rows,
519+
max_num_distinct,
520+
batch_gen_rng,
521+
array_gen_rng,
522+
DurationMillisecondType
523+
)
524+
}
525+
DataType::Duration(TimeUnit::Microsecond) => {
526+
generate_primitive_array!(
527+
self,
528+
num_rows,
529+
max_num_distinct,
530+
batch_gen_rng,
531+
array_gen_rng,
532+
DurationMicrosecondType
533+
)
534+
}
535+
DataType::Duration(TimeUnit::Nanosecond) => {
536+
generate_primitive_array!(
537+
self,
538+
num_rows,
539+
max_num_distinct,
540+
batch_gen_rng,
541+
array_gen_rng,
542+
DurationNanosecondType
543+
)
544+
}
487545
DataType::Timestamp(TimeUnit::Second, None) => {
488546
generate_primitive_array!(
489547
self,

test-utils/src/array_gen/primitive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl PrimitiveArrayGenerator {
6666
| DataType::Time32(_)
6767
| DataType::Time64(_)
6868
| DataType::Interval(_)
69+
| DataType::Duration(_)
6970
| DataType::Binary
7071
| DataType::LargeBinary
7172
| DataType::BinaryView

test-utils/src/array_gen/random_data.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818
use arrow::array::ArrowPrimitiveType;
1919
use arrow::datatypes::{
20-
i256, Date32Type, Date64Type, Decimal128Type, Decimal256Type, Float32Type,
21-
Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, IntervalDayTime,
22-
IntervalDayTimeType, IntervalMonthDayNano, IntervalMonthDayNanoType,
23-
IntervalYearMonthType, Time32MillisecondType, Time32SecondType,
24-
Time64MicrosecondType, Time64NanosecondType, TimestampMicrosecondType,
25-
TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType, UInt16Type,
26-
UInt32Type, UInt64Type, UInt8Type,
20+
i256, Date32Type, Date64Type, Decimal128Type, Decimal256Type,
21+
DurationMicrosecondType, DurationMillisecondType, DurationNanosecondType,
22+
DurationSecondType, Float32Type, Float64Type, Int16Type, Int32Type, Int64Type,
23+
Int8Type, IntervalDayTime, IntervalDayTimeType, IntervalMonthDayNano,
24+
IntervalMonthDayNanoType, IntervalYearMonthType, Time32MillisecondType,
25+
Time32SecondType, Time64MicrosecondType, Time64NanosecondType,
26+
TimestampMicrosecondType, TimestampMillisecondType, TimestampNanosecondType,
27+
TimestampSecondType, UInt16Type, UInt32Type, UInt64Type, UInt8Type,
2728
};
2829
use rand::distributions::Standard;
2930
use rand::prelude::Distribution;
@@ -71,6 +72,11 @@ basic_random_data!(TimestampSecondType);
7172
basic_random_data!(TimestampMillisecondType);
7273
basic_random_data!(TimestampMicrosecondType);
7374
basic_random_data!(TimestampNanosecondType);
75+
// Note DurationSecondType is restricted to i64::MIN / 1000 to i64::MAX / 1000
76+
// due to https://github.com/apache/arrow-rs/issues/7533 so handle it specially below
77+
basic_random_data!(DurationMillisecondType);
78+
basic_random_data!(DurationMicrosecondType);
79+
basic_random_data!(DurationNanosecondType);
7480

7581
impl RandomNativeData for Date64Type {
7682
fn generate_random_native_data(rng: &mut StdRng) -> Self::Native {
@@ -100,6 +106,15 @@ impl RandomNativeData for IntervalMonthDayNanoType {
100106
}
101107
}
102108

109+
// Restrict Duration(Seconds) to i64::MIN / 1000 to i64::MAX / 1000 to
110+
// avoid panics on pretty printing. See
111+
// https://github.com/apache/arrow-rs/issues/7533
112+
impl RandomNativeData for DurationSecondType {
113+
fn generate_random_native_data(rng: &mut StdRng) -> Self::Native {
114+
rng.gen::<i64>() / 1000
115+
}
116+
}
117+
103118
impl RandomNativeData for Decimal256Type {
104119
fn generate_random_native_data(rng: &mut StdRng) -> Self::Native {
105120
i256::from_parts(rng.gen::<u128>(), rng.gen::<i128>())

0 commit comments

Comments
 (0)