-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Impl spark bit not function #17155
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
base: main
Are you sure you want to change the base?
Impl spark bit not function #17155
Conversation
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.
Thanks for the PR, looks like some CI failures need to be addressed. Left some comments, with two more:
- Should the function be named
bitwise_not
to be consistent with the Spark function? - Would benefit from having some SLT tests
#[derive(Debug)] | ||
pub struct SparkBitNot { | ||
signature: Signature, | ||
aliases: Vec<String>, |
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.
Remove aliases
field if it's not used
Ok(match arg_types[0] { | ||
DataType::Int8 => DataType::Int8, | ||
DataType::Int16 => DataType::Int16, | ||
DataType::Int32 => DataType::Int32, | ||
DataType::Int64 => DataType::Int64, | ||
DataType::Null => DataType::Null, | ||
_ => { | ||
return exec_err!( | ||
"{} function can only accept integral arrays", | ||
self.name() | ||
) |
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.
I feel this should be encoded in the signature?
DataType::Int16 => bit_not_op!(value_array, Int16Type, Int16Array), | ||
DataType::Int32 => bit_not_op!(value_array, Int32Type, Int32Array), | ||
DataType::Int64 => bit_not_op!(value_array, Int64Type, Int64Array), | ||
_ => exec_err!("bit_not can't be evaluated because the expression's type is {:?}, not signed int", value_array.data_type()), |
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.
Why is this function limited to only signed integer types?
@@ -34,8 +36,9 @@ pub mod expr_fn { | |||
"Returns the number of bits set in the binary representation of the argument.", | |||
col | |||
)); | |||
export_functions!((bit_not, "Returns the result of a bitwise negation operation on the argument, where each bit in the binary representation is flipped, following two's complement arithmetic for signed integers.", col)); |
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.
Is it necessary to add the detail about two's complement here?
macro_rules! bit_not_op { | ||
($OPERAND:expr, $PT:ident, $AT:ident) => {{ | ||
let result: $AT = $OPERAND | ||
.as_primitive::<$PT>() | ||
.iter() | ||
.map(|x| x.map(|y| !y)) | ||
.collect(); | ||
Ok(Arc::new(result)) | ||
}}; | ||
} |
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.
It is possible to just use the arrow compute kernel here?
https://docs.rs/arrow/latest/arrow/compute/kernels/bitwise/fn.bitwise_not.html
Which issue does this PR close?
Part of [EPIC] Complete
datafusion-spark
Spark Compatible Functions #15914.Rationale for this change
What changes are included in this PR?
Implement spark bit_not function
Are these changes tested?
Added unit tests
Are there any user-facing changes?
Yes, new function on spark crate