-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix incorrect results in BitAnd GroupsAccumulator
#6957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,15 +49,16 @@ use arrow::compute::{bit_and, bit_or, bit_xor}; | |
| use datafusion_row::accessor::RowAccessor; | ||
|
|
||
| /// Creates a [`PrimitiveGroupsAccumulator`] with the specified | ||
| /// [`ArrowPrimitiveType`] which applies `$FN` to each element | ||
| /// [`ArrowPrimitiveType`] that initailizes each accumulator to $START | ||
| /// and applies `$FN` to each element | ||
| /// | ||
| /// [`ArrowPrimitiveType`]: arrow::datatypes::ArrowPrimitiveType | ||
| macro_rules! instantiate_primitive_accumulator { | ||
| ($SELF:expr, $PRIMTYPE:ident, $FN:expr) => {{ | ||
| Ok(Box::new(PrimitiveGroupsAccumulator::<$PRIMTYPE, _>::new( | ||
| &$SELF.data_type, | ||
| $FN, | ||
| ))) | ||
| macro_rules! instantiate_accumulator { | ||
| ($SELF:expr, $START:expr, $PRIMTYPE:ident, $FN:expr) => {{ | ||
| Ok(Box::new( | ||
| PrimitiveGroupsAccumulator::<$PRIMTYPE, _>::new(&$SELF.data_type, $FN) | ||
| .with_starting_value($START), | ||
| )) | ||
| }}; | ||
| } | ||
|
|
||
|
|
@@ -279,35 +280,31 @@ impl AggregateExpr for BitAnd { | |
| use std::ops::BitAndAssign; | ||
| match self.data_type { | ||
| DataType::Int8 => { | ||
| instantiate_primitive_accumulator!(self, Int8Type, |x, y| x | ||
| .bitand_assign(y)) | ||
| instantiate_accumulator!(self, -1, Int8Type, |x, y| x.bitand_assign(y)) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the fix is passing in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fix looks good. It's better to leave a comment like above in the code.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment added in #6964 |
||
| } | ||
| DataType::Int16 => { | ||
| instantiate_primitive_accumulator!(self, Int16Type, |x, y| x | ||
| .bitand_assign(y)) | ||
| instantiate_accumulator!(self, -1, Int16Type, |x, y| x.bitand_assign(y)) | ||
| } | ||
| DataType::Int32 => { | ||
| instantiate_primitive_accumulator!(self, Int32Type, |x, y| x | ||
| .bitand_assign(y)) | ||
| instantiate_accumulator!(self, -1, Int32Type, |x, y| x.bitand_assign(y)) | ||
| } | ||
| DataType::Int64 => { | ||
| instantiate_primitive_accumulator!(self, Int64Type, |x, y| x | ||
| .bitand_assign(y)) | ||
| instantiate_accumulator!(self, -1, Int64Type, |x, y| x.bitand_assign(y)) | ||
| } | ||
| DataType::UInt8 => { | ||
| instantiate_primitive_accumulator!(self, UInt8Type, |x, y| x | ||
| instantiate_accumulator!(self, u8::MAX, UInt8Type, |x, y| x | ||
| .bitand_assign(y)) | ||
| } | ||
| DataType::UInt16 => { | ||
| instantiate_primitive_accumulator!(self, UInt16Type, |x, y| x | ||
| instantiate_accumulator!(self, u16::MAX, UInt16Type, |x, y| x | ||
| .bitand_assign(y)) | ||
| } | ||
| DataType::UInt32 => { | ||
| instantiate_primitive_accumulator!(self, UInt32Type, |x, y| x | ||
| instantiate_accumulator!(self, u32::MAX, UInt32Type, |x, y| x | ||
| .bitand_assign(y)) | ||
| } | ||
| DataType::UInt64 => { | ||
| instantiate_primitive_accumulator!(self, UInt64Type, |x, y| x | ||
| instantiate_accumulator!(self, u64::MAX, UInt64Type, |x, y| x | ||
| .bitand_assign(y)) | ||
| } | ||
|
|
||
|
|
@@ -517,36 +514,28 @@ impl AggregateExpr for BitOr { | |
| use std::ops::BitOrAssign; | ||
| match self.data_type { | ||
| DataType::Int8 => { | ||
| instantiate_primitive_accumulator!(self, Int8Type, |x, y| x | ||
| .bitor_assign(y)) | ||
| instantiate_accumulator!(self, 0, Int8Type, |x, y| x.bitor_assign(y)) | ||
| } | ||
| DataType::Int16 => { | ||
| instantiate_primitive_accumulator!(self, Int16Type, |x, y| x | ||
| .bitor_assign(y)) | ||
| instantiate_accumulator!(self, 0, Int16Type, |x, y| x.bitor_assign(y)) | ||
| } | ||
| DataType::Int32 => { | ||
| instantiate_primitive_accumulator!(self, Int32Type, |x, y| x | ||
| .bitor_assign(y)) | ||
| instantiate_accumulator!(self, 0, Int32Type, |x, y| x.bitor_assign(y)) | ||
| } | ||
| DataType::Int64 => { | ||
| instantiate_primitive_accumulator!(self, Int64Type, |x, y| x | ||
| .bitor_assign(y)) | ||
| instantiate_accumulator!(self, 0, Int64Type, |x, y| x.bitor_assign(y)) | ||
| } | ||
| DataType::UInt8 => { | ||
| instantiate_primitive_accumulator!(self, UInt8Type, |x, y| x | ||
| .bitor_assign(y)) | ||
| instantiate_accumulator!(self, 0, UInt8Type, |x, y| x.bitor_assign(y)) | ||
| } | ||
| DataType::UInt16 => { | ||
| instantiate_primitive_accumulator!(self, UInt16Type, |x, y| x | ||
| .bitor_assign(y)) | ||
| instantiate_accumulator!(self, 0, UInt16Type, |x, y| x.bitor_assign(y)) | ||
| } | ||
| DataType::UInt32 => { | ||
| instantiate_primitive_accumulator!(self, UInt32Type, |x, y| x | ||
| .bitor_assign(y)) | ||
| instantiate_accumulator!(self, 0, UInt32Type, |x, y| x.bitor_assign(y)) | ||
| } | ||
| DataType::UInt64 => { | ||
| instantiate_primitive_accumulator!(self, UInt64Type, |x, y| x | ||
| .bitor_assign(y)) | ||
| instantiate_accumulator!(self, 0, UInt64Type, |x, y| x.bitor_assign(y)) | ||
| } | ||
|
|
||
| _ => Err(DataFusionError::NotImplemented(format!( | ||
|
|
@@ -756,36 +745,28 @@ impl AggregateExpr for BitXor { | |
| use std::ops::BitXorAssign; | ||
| match self.data_type { | ||
| DataType::Int8 => { | ||
| instantiate_primitive_accumulator!(self, Int8Type, |x, y| x | ||
| .bitxor_assign(y)) | ||
| instantiate_accumulator!(self, 0, Int8Type, |x, y| x.bitxor_assign(y)) | ||
| } | ||
| DataType::Int16 => { | ||
| instantiate_primitive_accumulator!(self, Int16Type, |x, y| x | ||
| .bitxor_assign(y)) | ||
| instantiate_accumulator!(self, 0, Int16Type, |x, y| x.bitxor_assign(y)) | ||
| } | ||
| DataType::Int32 => { | ||
| instantiate_primitive_accumulator!(self, Int32Type, |x, y| x | ||
| .bitxor_assign(y)) | ||
| instantiate_accumulator!(self, 0, Int32Type, |x, y| x.bitxor_assign(y)) | ||
| } | ||
| DataType::Int64 => { | ||
| instantiate_primitive_accumulator!(self, Int64Type, |x, y| x | ||
| .bitxor_assign(y)) | ||
| instantiate_accumulator!(self, 0, Int64Type, |x, y| x.bitxor_assign(y)) | ||
| } | ||
| DataType::UInt8 => { | ||
| instantiate_primitive_accumulator!(self, UInt8Type, |x, y| x | ||
| .bitxor_assign(y)) | ||
| instantiate_accumulator!(self, 0, UInt8Type, |x, y| x.bitxor_assign(y)) | ||
| } | ||
| DataType::UInt16 => { | ||
| instantiate_primitive_accumulator!(self, UInt16Type, |x, y| x | ||
| .bitxor_assign(y)) | ||
| instantiate_accumulator!(self, 0, UInt16Type, |x, y| x.bitxor_assign(y)) | ||
| } | ||
| DataType::UInt32 => { | ||
| instantiate_primitive_accumulator!(self, UInt32Type, |x, y| x | ||
| .bitxor_assign(y)) | ||
| instantiate_accumulator!(self, 0, UInt32Type, |x, y| x.bitxor_assign(y)) | ||
| } | ||
| DataType::UInt64 => { | ||
| instantiate_primitive_accumulator!(self, UInt64Type, |x, y| x | ||
| .bitxor_assign(y)) | ||
| instantiate_accumulator!(self, 0, UInt64Type, |x, y| x.bitxor_assign(y)) | ||
| } | ||
|
|
||
| _ => Err(DataFusionError::NotImplemented(format!( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before this PR, this test fails like