@@ -49,15 +49,16 @@ use arrow::compute::{bit_and, bit_or, bit_xor};
49
49
use datafusion_row:: accessor:: RowAccessor ;
50
50
51
51
/// Creates a [`PrimitiveGroupsAccumulator`] with the specified
52
- /// [`ArrowPrimitiveType`] which applies `$FN` to each element
52
+ /// [`ArrowPrimitiveType`] that initailizes each accumulator to $START
53
+ /// and applies `$FN` to each element
53
54
///
54
55
/// [`ArrowPrimitiveType`]: arrow::datatypes::ArrowPrimitiveType
55
- macro_rules! instantiate_primitive_accumulator {
56
- ( $SELF: expr, $PRIMTYPE: ident, $FN: expr) => { {
57
- Ok ( Box :: new( PrimitiveGroupsAccumulator :: <$PRIMTYPE , _> :: new (
58
- & $SELF. data_type,
59
- $FN ,
60
- ) ) )
56
+ macro_rules! instantiate_accumulator {
57
+ ( $SELF: expr, $START : expr , $ PRIMTYPE: ident, $FN: expr) => { {
58
+ Ok ( Box :: new(
59
+ PrimitiveGroupsAccumulator :: <$PRIMTYPE , _> :: new ( & $SELF. data_type, $FN )
60
+ . with_starting_value ( $START ) ,
61
+ ) )
61
62
} } ;
62
63
}
63
64
@@ -279,35 +280,31 @@ impl AggregateExpr for BitAnd {
279
280
use std:: ops:: BitAndAssign ;
280
281
match self . data_type {
281
282
DataType :: Int8 => {
282
- instantiate_primitive_accumulator ! ( self , Int8Type , |x, y| x
283
- . bitand_assign( y) )
283
+ instantiate_accumulator ! ( self , -1 , Int8Type , |x, y| x. bitand_assign( y) )
284
284
}
285
285
DataType :: Int16 => {
286
- instantiate_primitive_accumulator ! ( self , Int16Type , |x, y| x
287
- . bitand_assign( y) )
286
+ instantiate_accumulator ! ( self , -1 , Int16Type , |x, y| x. bitand_assign( y) )
288
287
}
289
288
DataType :: Int32 => {
290
- instantiate_primitive_accumulator ! ( self , Int32Type , |x, y| x
291
- . bitand_assign( y) )
289
+ instantiate_accumulator ! ( self , -1 , Int32Type , |x, y| x. bitand_assign( y) )
292
290
}
293
291
DataType :: Int64 => {
294
- instantiate_primitive_accumulator ! ( self , Int64Type , |x, y| x
295
- . bitand_assign( y) )
292
+ instantiate_accumulator ! ( self , -1 , Int64Type , |x, y| x. bitand_assign( y) )
296
293
}
297
294
DataType :: UInt8 => {
298
- instantiate_primitive_accumulator ! ( self , UInt8Type , |x, y| x
295
+ instantiate_accumulator ! ( self , u8 :: MAX , UInt8Type , |x, y| x
299
296
. bitand_assign( y) )
300
297
}
301
298
DataType :: UInt16 => {
302
- instantiate_primitive_accumulator ! ( self , UInt16Type , |x, y| x
299
+ instantiate_accumulator ! ( self , u16 :: MAX , UInt16Type , |x, y| x
303
300
. bitand_assign( y) )
304
301
}
305
302
DataType :: UInt32 => {
306
- instantiate_primitive_accumulator ! ( self , UInt32Type , |x, y| x
303
+ instantiate_accumulator ! ( self , u32 :: MAX , UInt32Type , |x, y| x
307
304
. bitand_assign( y) )
308
305
}
309
306
DataType :: UInt64 => {
310
- instantiate_primitive_accumulator ! ( self , UInt64Type , |x, y| x
307
+ instantiate_accumulator ! ( self , u64 :: MAX , UInt64Type , |x, y| x
311
308
. bitand_assign( y) )
312
309
}
313
310
@@ -517,36 +514,28 @@ impl AggregateExpr for BitOr {
517
514
use std:: ops:: BitOrAssign ;
518
515
match self . data_type {
519
516
DataType :: Int8 => {
520
- instantiate_primitive_accumulator ! ( self , Int8Type , |x, y| x
521
- . bitor_assign( y) )
517
+ instantiate_accumulator ! ( self , 0 , Int8Type , |x, y| x. bitor_assign( y) )
522
518
}
523
519
DataType :: Int16 => {
524
- instantiate_primitive_accumulator ! ( self , Int16Type , |x, y| x
525
- . bitor_assign( y) )
520
+ instantiate_accumulator ! ( self , 0 , Int16Type , |x, y| x. bitor_assign( y) )
526
521
}
527
522
DataType :: Int32 => {
528
- instantiate_primitive_accumulator ! ( self , Int32Type , |x, y| x
529
- . bitor_assign( y) )
523
+ instantiate_accumulator ! ( self , 0 , Int32Type , |x, y| x. bitor_assign( y) )
530
524
}
531
525
DataType :: Int64 => {
532
- instantiate_primitive_accumulator ! ( self , Int64Type , |x, y| x
533
- . bitor_assign( y) )
526
+ instantiate_accumulator ! ( self , 0 , Int64Type , |x, y| x. bitor_assign( y) )
534
527
}
535
528
DataType :: UInt8 => {
536
- instantiate_primitive_accumulator ! ( self , UInt8Type , |x, y| x
537
- . bitor_assign( y) )
529
+ instantiate_accumulator ! ( self , 0 , UInt8Type , |x, y| x. bitor_assign( y) )
538
530
}
539
531
DataType :: UInt16 => {
540
- instantiate_primitive_accumulator ! ( self , UInt16Type , |x, y| x
541
- . bitor_assign( y) )
532
+ instantiate_accumulator ! ( self , 0 , UInt16Type , |x, y| x. bitor_assign( y) )
542
533
}
543
534
DataType :: UInt32 => {
544
- instantiate_primitive_accumulator ! ( self , UInt32Type , |x, y| x
545
- . bitor_assign( y) )
535
+ instantiate_accumulator ! ( self , 0 , UInt32Type , |x, y| x. bitor_assign( y) )
546
536
}
547
537
DataType :: UInt64 => {
548
- instantiate_primitive_accumulator ! ( self , UInt64Type , |x, y| x
549
- . bitor_assign( y) )
538
+ instantiate_accumulator ! ( self , 0 , UInt64Type , |x, y| x. bitor_assign( y) )
550
539
}
551
540
552
541
_ => Err ( DataFusionError :: NotImplemented ( format ! (
@@ -756,36 +745,28 @@ impl AggregateExpr for BitXor {
756
745
use std:: ops:: BitXorAssign ;
757
746
match self . data_type {
758
747
DataType :: Int8 => {
759
- instantiate_primitive_accumulator ! ( self , Int8Type , |x, y| x
760
- . bitxor_assign( y) )
748
+ instantiate_accumulator ! ( self , 0 , Int8Type , |x, y| x. bitxor_assign( y) )
761
749
}
762
750
DataType :: Int16 => {
763
- instantiate_primitive_accumulator ! ( self , Int16Type , |x, y| x
764
- . bitxor_assign( y) )
751
+ instantiate_accumulator ! ( self , 0 , Int16Type , |x, y| x. bitxor_assign( y) )
765
752
}
766
753
DataType :: Int32 => {
767
- instantiate_primitive_accumulator ! ( self , Int32Type , |x, y| x
768
- . bitxor_assign( y) )
754
+ instantiate_accumulator ! ( self , 0 , Int32Type , |x, y| x. bitxor_assign( y) )
769
755
}
770
756
DataType :: Int64 => {
771
- instantiate_primitive_accumulator ! ( self , Int64Type , |x, y| x
772
- . bitxor_assign( y) )
757
+ instantiate_accumulator ! ( self , 0 , Int64Type , |x, y| x. bitxor_assign( y) )
773
758
}
774
759
DataType :: UInt8 => {
775
- instantiate_primitive_accumulator ! ( self , UInt8Type , |x, y| x
776
- . bitxor_assign( y) )
760
+ instantiate_accumulator ! ( self , 0 , UInt8Type , |x, y| x. bitxor_assign( y) )
777
761
}
778
762
DataType :: UInt16 => {
779
- instantiate_primitive_accumulator ! ( self , UInt16Type , |x, y| x
780
- . bitxor_assign( y) )
763
+ instantiate_accumulator ! ( self , 0 , UInt16Type , |x, y| x. bitxor_assign( y) )
781
764
}
782
765
DataType :: UInt32 => {
783
- instantiate_primitive_accumulator ! ( self , UInt32Type , |x, y| x
784
- . bitxor_assign( y) )
766
+ instantiate_accumulator ! ( self , 0 , UInt32Type , |x, y| x. bitxor_assign( y) )
785
767
}
786
768
DataType :: UInt64 => {
787
- instantiate_primitive_accumulator ! ( self , UInt64Type , |x, y| x
788
- . bitxor_assign( y) )
769
+ instantiate_accumulator ! ( self , 0 , UInt64Type , |x, y| x. bitxor_assign( y) )
789
770
}
790
771
791
772
_ => Err ( DataFusionError :: NotImplemented ( format ! (
0 commit comments