@@ -23,10 +23,10 @@ mod min_max_struct;
2323
2424use arrow:: array:: ArrayRef ;
2525use arrow:: datatypes:: {
26- DataType , Decimal128Type , Decimal256Type , DurationMicrosecondType ,
27- DurationMillisecondType , DurationNanosecondType , DurationSecondType , Float16Type ,
28- Float32Type , Float64Type , Int16Type , Int32Type , Int64Type , Int8Type , UInt16Type ,
29- UInt32Type , UInt64Type , UInt8Type ,
26+ DataType , Decimal128Type , Decimal256Type , Decimal32Type , Decimal64Type ,
27+ DurationMicrosecondType , DurationMillisecondType , DurationNanosecondType ,
28+ DurationSecondType , Float16Type , Float32Type , Float64Type , Int16Type , Int32Type ,
29+ Int64Type , Int8Type , UInt16Type , UInt32Type , UInt64Type , UInt8Type ,
3030} ;
3131use datafusion_common:: stats:: Precision ;
3232use datafusion_common:: {
@@ -323,6 +323,12 @@ impl AggregateUDFImpl for Max {
323323 Duration ( Nanosecond ) => {
324324 primitive_max_accumulator ! ( data_type, i64 , DurationNanosecondType )
325325 }
326+ Decimal32 ( _, _) => {
327+ primitive_max_accumulator ! ( data_type, i32 , Decimal32Type )
328+ }
329+ Decimal64 ( _, _) => {
330+ primitive_max_accumulator ! ( data_type, i64 , Decimal64Type )
331+ }
326332 Decimal128 ( _, _) => {
327333 primitive_max_accumulator ! ( data_type, i128 , Decimal128Type )
328334 }
@@ -484,6 +490,32 @@ macro_rules! min_max {
484490 ( $VALUE: expr, $DELTA: expr, $OP: ident) => { {
485491 Ok ( match ( $VALUE, $DELTA) {
486492 ( ScalarValue :: Null , ScalarValue :: Null ) => ScalarValue :: Null ,
493+ (
494+ lhs @ ScalarValue :: Decimal32 ( lhsv, lhsp, lhss) ,
495+ rhs @ ScalarValue :: Decimal32 ( rhsv, rhsp, rhss)
496+ ) => {
497+ if lhsp. eq( rhsp) && lhss. eq( rhss) {
498+ typed_min_max!( lhsv, rhsv, Decimal32 , $OP, lhsp, lhss)
499+ } else {
500+ return internal_err!(
501+ "MIN/MAX is not expected to receive scalars of incompatible types {:?}" ,
502+ ( lhs, rhs)
503+ ) ;
504+ }
505+ }
506+ (
507+ lhs @ ScalarValue :: Decimal64 ( lhsv, lhsp, lhss) ,
508+ rhs @ ScalarValue :: Decimal64 ( rhsv, rhsp, rhss)
509+ ) => {
510+ if lhsp. eq( rhsp) && lhss. eq( rhss) {
511+ typed_min_max!( lhsv, rhsv, Decimal64 , $OP, lhsp, lhss)
512+ } else {
513+ return internal_err!(
514+ "MIN/MAX is not expected to receive scalars of incompatible types {:?}" ,
515+ ( lhs, rhs)
516+ ) ;
517+ }
518+ }
487519 (
488520 lhs @ ScalarValue :: Decimal128 ( lhsv, lhsp, lhss) ,
489521 rhs @ ScalarValue :: Decimal128 ( rhsv, rhsp, rhss)
@@ -919,6 +951,8 @@ impl AggregateUDFImpl for Min {
919951 | Float16
920952 | Float32
921953 | Float64
954+ | Decimal32 ( _, _)
955+ | Decimal64 ( _, _)
922956 | Decimal128 ( _, _)
923957 | Decimal256 ( _, _)
924958 | Date32
@@ -1000,6 +1034,12 @@ impl AggregateUDFImpl for Min {
10001034 Duration ( Nanosecond ) => {
10011035 primitive_min_accumulator ! ( data_type, i64 , DurationNanosecondType )
10021036 }
1037+ Decimal32 ( _, _) => {
1038+ primitive_min_accumulator ! ( data_type, i32 , Decimal32Type )
1039+ }
1040+ Decimal64 ( _, _) => {
1041+ primitive_min_accumulator ! ( data_type, i64 , Decimal64Type )
1042+ }
10031043 Decimal128 ( _, _) => {
10041044 primitive_min_accumulator ! ( data_type, i128 , Decimal128Type )
10051045 }
0 commit comments