1818use std:: sync:: Arc ;
1919
2020use arrow:: datatypes:: {
21- Date32Type , Date64Type , Float32Type , Float64Type , Int16Type , Int32Type , Int64Type ,
22- Int8Type , UInt16Type , UInt32Type , UInt64Type , UInt8Type ,
21+ ByteArrayType , ByteViewType , Date32Type , Date64Type , Decimal128Type , Decimal256Type ,
22+ Float32Type , Float64Type , Int16Type , Int32Type , Int64Type , Int8Type ,
23+ IntervalDayTimeType , IntervalMonthDayNanoType , IntervalYearMonthType , LargeUtf8Type ,
24+ StringViewType , Time32MillisecondType , Time32SecondType , Time64MicrosecondType ,
25+ Time64NanosecondType , UInt16Type , UInt32Type , UInt64Type , UInt8Type , Utf8Type ,
2326} ;
2427use arrow_array:: { ArrayRef , RecordBatch } ;
25- use arrow_schema:: { DataType , Field , Schema } ;
28+ use arrow_schema:: { DataType , Field , IntervalUnit , Schema , TimeUnit } ;
2629use datafusion_common:: { arrow_datafusion_err, DataFusionError , Result } ;
2730use datafusion_physical_expr:: { expressions:: col, PhysicalSortExpr } ;
2831use datafusion_physical_expr_common:: sort_expr:: LexOrdering ;
@@ -32,7 +35,7 @@ use rand::{
3235 thread_rng, Rng , SeedableRng ,
3336} ;
3437use test_utils:: {
35- array_gen:: { PrimitiveArrayGenerator , StringArrayGenerator } ,
38+ array_gen:: { DecimalArrayGenerator , PrimitiveArrayGenerator , StringArrayGenerator } ,
3639 stagger_batch,
3740} ;
3841
@@ -219,7 +222,7 @@ struct RecordBatchGenerator {
219222}
220223
221224macro_rules! generate_string_array {
222- ( $SELF: ident, $NUM_ROWS: ident, $MAX_NUM_DISTINCT: expr, $BATCH_GEN_RNG: ident, $ARRAY_GEN_RNG: ident, $OFFSET_TYPE : ty ) => { {
225+ ( $SELF: ident, $NUM_ROWS: ident, $MAX_NUM_DISTINCT: expr, $BATCH_GEN_RNG: ident, $ARRAY_GEN_RNG: ident, $ARROW_TYPE : ident ) => { {
223226 let null_pct_idx = $BATCH_GEN_RNG. gen_range( 0 ..$SELF. candidate_null_pcts. len( ) ) ;
224227 let null_pct = $SELF. candidate_null_pcts[ null_pct_idx] ;
225228 let max_len = $BATCH_GEN_RNG. gen_range( 1 ..50 ) ;
@@ -232,25 +235,47 @@ macro_rules! generate_string_array {
232235 rng: $ARRAY_GEN_RNG,
233236 } ;
234237
235- generator. gen_data:: <$OFFSET_TYPE>( )
238+ match $ARROW_TYPE:: DATA_TYPE {
239+ DataType :: Utf8 => generator. gen_data:: <i32 >( ) ,
240+ DataType :: LargeUtf8 => generator. gen_data:: <i64 >( ) ,
241+ DataType :: Utf8View => generator. gen_string_view( ) ,
242+ _ => unreachable!( ) ,
243+ }
244+ } } ;
245+ }
246+
247+ macro_rules! generate_decimal_array {
248+ ( $SELF: ident, $NUM_ROWS: ident, $MAX_NUM_DISTINCT: expr, $BATCH_GEN_RNG: ident, $ARRAY_GEN_RNG: ident, $PRECISION: ident, $SCALE: ident, $ARROW_TYPE: ident) => { {
249+ let null_pct_idx = $BATCH_GEN_RNG. gen_range( 0 ..$SELF. candidate_null_pcts. len( ) ) ;
250+ let null_pct = $SELF. candidate_null_pcts[ null_pct_idx] ;
251+
252+ let mut generator = DecimalArrayGenerator {
253+ precision: $PRECISION,
254+ scale: $SCALE,
255+ num_decimals: $NUM_ROWS,
256+ num_distinct_decimals: $MAX_NUM_DISTINCT,
257+ null_pct,
258+ rng: $ARRAY_GEN_RNG,
259+ } ;
260+
261+ generator. gen_data:: <$ARROW_TYPE>( )
236262 } } ;
237263}
238264
239265macro_rules! generate_primitive_array {
240- ( $SELF: ident, $NUM_ROWS: ident, $MAX_NUM_DISTINCT: expr, $BATCH_GEN_RNG: ident, $ARRAY_GEN_RNG: ident, $ARROW_TYPE: ident) => {
241- paste:: paste! { {
242- let null_pct_idx = $BATCH_GEN_RNG. gen_range( 0 ..$SELF. candidate_null_pcts. len( ) ) ;
243- let null_pct = $SELF. candidate_null_pcts[ null_pct_idx] ;
244-
245- let mut generator = PrimitiveArrayGenerator {
246- num_primitives: $NUM_ROWS,
247- num_distinct_primitives: $MAX_NUM_DISTINCT,
248- null_pct,
249- rng: $ARRAY_GEN_RNG,
250- } ;
251-
252- generator. gen_data:: <$ARROW_TYPE>( )
253- } } }
266+ ( $SELF: ident, $NUM_ROWS: ident, $MAX_NUM_DISTINCT: expr, $BATCH_GEN_RNG: ident, $ARRAY_GEN_RNG: ident, $ARROW_TYPE: ident) => { {
267+ let null_pct_idx = $BATCH_GEN_RNG. gen_range( 0 ..$SELF. candidate_null_pcts. len( ) ) ;
268+ let null_pct = $SELF. candidate_null_pcts[ null_pct_idx] ;
269+
270+ let mut generator = PrimitiveArrayGenerator {
271+ num_primitives: $NUM_ROWS,
272+ num_distinct_primitives: $MAX_NUM_DISTINCT,
273+ null_pct,
274+ rng: $ARRAY_GEN_RNG,
275+ } ;
276+
277+ generator. gen_data:: <$ARROW_TYPE>( )
278+ } } ;
254279}
255280
256281impl RecordBatchGenerator {
@@ -432,14 +457,108 @@ impl RecordBatchGenerator {
432457 Date64Type
433458 )
434459 }
460+ DataType :: Time32 ( TimeUnit :: Second ) => {
461+ generate_primitive_array ! (
462+ self ,
463+ num_rows,
464+ max_num_distinct,
465+ batch_gen_rng,
466+ array_gen_rng,
467+ Time32SecondType
468+ )
469+ }
470+ DataType :: Time32 ( TimeUnit :: Millisecond ) => {
471+ generate_primitive_array ! (
472+ self ,
473+ num_rows,
474+ max_num_distinct,
475+ batch_gen_rng,
476+ array_gen_rng,
477+ Time32MillisecondType
478+ )
479+ }
480+ DataType :: Time64 ( TimeUnit :: Microsecond ) => {
481+ generate_primitive_array ! (
482+ self ,
483+ num_rows,
484+ max_num_distinct,
485+ batch_gen_rng,
486+ array_gen_rng,
487+ Time64MicrosecondType
488+ )
489+ }
490+ DataType :: Time64 ( TimeUnit :: Nanosecond ) => {
491+ generate_primitive_array ! (
492+ self ,
493+ num_rows,
494+ max_num_distinct,
495+ batch_gen_rng,
496+ array_gen_rng,
497+ Time64NanosecondType
498+ )
499+ }
500+ DataType :: Interval ( IntervalUnit :: YearMonth ) => {
501+ generate_primitive_array ! (
502+ self ,
503+ num_rows,
504+ max_num_distinct,
505+ batch_gen_rng,
506+ array_gen_rng,
507+ IntervalYearMonthType
508+ )
509+ }
510+ DataType :: Interval ( IntervalUnit :: DayTime ) => {
511+ generate_primitive_array ! (
512+ self ,
513+ num_rows,
514+ max_num_distinct,
515+ batch_gen_rng,
516+ array_gen_rng,
517+ IntervalDayTimeType
518+ )
519+ }
520+ DataType :: Interval ( IntervalUnit :: MonthDayNano ) => {
521+ generate_primitive_array ! (
522+ self ,
523+ num_rows,
524+ max_num_distinct,
525+ batch_gen_rng,
526+ array_gen_rng,
527+ IntervalMonthDayNanoType
528+ )
529+ }
530+ DataType :: Decimal128 ( precision, scale) => {
531+ generate_decimal_array ! (
532+ self ,
533+ num_rows,
534+ max_num_distinct,
535+ batch_gen_rng,
536+ array_gen_rng,
537+ precision,
538+ scale,
539+ Decimal128Type
540+ )
541+ }
542+ DataType :: Decimal256 ( precision, scale) => {
543+ generate_decimal_array ! (
544+ self ,
545+ num_rows,
546+ max_num_distinct,
547+ batch_gen_rng,
548+ array_gen_rng,
549+ precision,
550+ scale,
551+ Decimal256Type
552+ )
553+ }
435554 DataType :: Utf8 => {
436555 generate_string_array ! (
437556 self ,
438557 num_rows,
439558 max_num_distinct,
440559 batch_gen_rng,
441560 array_gen_rng,
442- i32
561+ Utf8Type
443562 )
444563 }
445564 DataType :: LargeUtf8 => {
@@ -449,7 +568,17 @@ impl RecordBatchGenerator {
449568 max_num_distinct,
450569 batch_gen_rng,
451570 array_gen_rng,
452- i64
571+ LargeUtf8Type
572+ )
573+ }
574+ DataType :: Utf8View => {
575+ generate_string_array ! (
576+ self ,
577+ num_rows,
578+ max_num_distinct,
579+ batch_gen_rng,
580+ array_gen_rng,
581+ StringViewType
453582 )
454583 }
455584 _ => {
0 commit comments