@@ -47,7 +47,7 @@ use datafusion_expr::Accumulator;
4747pub struct Sum {
4848 name : String ,
4949 data_type : DataType ,
50- /// `return_data_type` is different for ArrayAggregate cases, see `datafusion_expr::type_coercion::aggregates::sum_return_type`
50+ // `return_data_type` is different for ArrayAggregate cases, see `datafusion_expr::type_coercion::aggregates::sum_return_type`
5151 return_data_type : DataType ,
5252 expr : Arc < dyn PhysicalExpr > ,
5353 nullable : bool ,
@@ -90,6 +90,27 @@ macro_rules! downcast_sum {
9090}
9191pub ( crate ) use downcast_sum;
9292
93+ // TODO: Replace with `downcast_sum` after most of the AggregateExpr differentiate `return_data_type` and `data_type`
94+ // The reason we have this is because using the name `return_data_type` makes more much sense to me,
95+ // instead of changing `data_type` to `return_data_type` all the AggregateExpr that have `downcast_sum`, introduce v2 is better.
96+ macro_rules! downcast_sum_v2 {
97+ ( $s: ident, $helper: ident) => {
98+ match $s. return_data_type {
99+ DataType :: UInt64 => $helper!( UInt64Type , $s. return_data_type) ,
100+ DataType :: Int64 => $helper!( Int64Type , $s. return_data_type) ,
101+ DataType :: Float64 => $helper!( Float64Type , $s. return_data_type) ,
102+ DataType :: Decimal128 ( _, _) => $helper!( Decimal128Type , $s. return_data_type) ,
103+ DataType :: Decimal256 ( _, _) => $helper!( Decimal256Type , $s. return_data_type) ,
104+ _ => not_impl_err!(
105+ "Sum not supported for {}: {}" ,
106+ $s. name,
107+ $s. return_data_type
108+ ) ,
109+ }
110+ } ;
111+ }
112+ pub ( crate ) use downcast_sum_v2;
113+
93114impl AggregateExpr for Sum {
94115 /// Return a reference to Any that can be used for downcasting
95116 fn as_any ( & self ) -> & dyn Any {
@@ -146,7 +167,7 @@ impl AggregateExpr for Sum {
146167 Ok ( Box :: new( SumAccumulator :: <$t>:: new( $dt. clone( ) ) ) )
147168 } ;
148169 }
149- downcast_sum ! ( self , helper)
170+ downcast_sum_v2 ! ( self , helper)
150171 }
151172
152173 fn state_fields ( & self ) -> Result < Vec < Field > > {
@@ -178,7 +199,7 @@ impl AggregateExpr for Sum {
178199 ) ) )
179200 } ;
180201 }
181- downcast_sum ! ( self , helper)
202+ downcast_sum_v2 ! ( self , helper)
182203 }
183204
184205 fn reverse_expr ( & self ) -> Option < Arc < dyn AggregateExpr > > {
@@ -191,7 +212,7 @@ impl AggregateExpr for Sum {
191212 Ok ( Box :: new( SlidingSumAccumulator :: <$t>:: new( $dt. clone( ) ) ) )
192213 } ;
193214 }
194- downcast_sum ! ( self , helper)
215+ downcast_sum_v2 ! ( self , helper)
195216 }
196217}
197218
0 commit comments