Skip to content

Conversation

kazantsev-maksim
Copy link

@kazantsev-maksim kazantsev-maksim commented Aug 12, 2025

Which issue does this PR close?

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

@github-actions github-actions bot added the spark label Aug 12, 2025
@alamb alamb removed the spark label Aug 12, 2025
@github-actions github-actions bot added the spark label Aug 14, 2025
Copy link
Contributor

@Jefffrey Jefffrey left a 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:

#[derive(Debug)]
pub struct SparkBitNot {
signature: Signature,
aliases: Vec<String>,
Copy link
Contributor

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

Comment on lines +67 to +77
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()
)
Copy link
Contributor

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()),
Copy link
Contributor

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));
Copy link
Contributor

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?

Comment on lines +90 to +99
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))
}};
}
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[datafusion-spark] Implement Spark bitwise_not function
3 participants