alamb commented on code in PR #3037:
URL: https://github.com/apache/arrow-datafusion/pull/3037#discussion_r944821596
##########
datafusion/physical-expr/src/expressions/binary/kernels.rs:
##########
@@ -49,7 +50,7 @@ macro_rules! binary_bitwise_array_op {
/// like int64, int32.
/// It is used to do bitwise operation on an array with a scalar.
macro_rules! binary_bitwise_array_scalar {
Review Comment:
I think it makes sense -- thank you
##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -2481,6 +2492,34 @@ mod tests {
Ok(())
}
+ #[test]
+ fn bitwise_shift_array_test() -> Result<()> {
+ let input = Arc::new(Int32Array::from(vec![Some(2), None, Some(10)]))
as ArrayRef;
+ let modules =
+ Arc::new(Int32Array::from(vec![Some(2), Some(4), Some(8)])) as
ArrayRef;
+ let mut result = bitwise_shift_left(input.clone(), modules.clone())?;
+
+ let expected = Int32Array::from(vec![Some(8), None, Some(2560)]);
+ assert_eq!(result.as_ref(), &expected);
+
+ result = bitwise_shift_right(result.clone(), modules.clone())?;
+ assert_eq!(result.as_ref(), &input);
+
+ Ok(())
+ }
+
+ #[test]
+ fn bitwise_shift_array_overflow_test() -> Result<()> {
+ let input = Arc::new(Int32Array::from(vec![Some(2)])) as ArrayRef;
+ let modules = Arc::new(Int32Array::from(vec![Some(100)])) as ArrayRef;
+ let result = bitwise_shift_left(input.clone(), modules.clone())?;
+
+ let expected = Int32Array::from(vec![Some(32)]);
Review Comment:
TIL `2 << 100` = `32` 🤯
https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=b0682ca51f798793e784b852e28dc4a8
##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -2481,6 +2492,34 @@ mod tests {
Ok(())
}
+ #[test]
+ fn bitwise_shift_array_test() -> Result<()> {
+ let input = Arc::new(Int32Array::from(vec![Some(2), None, Some(10)]))
as ArrayRef;
+ let modules =
Review Comment:
I suggest a test for when the `modules` is Null (you cover NULL for the
input already)
##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -2494,4 +2533,19 @@ mod tests {
assert_eq!(result.as_ref(), &expected);
Ok(())
}
+
+ #[test]
+ fn bitwise_shift_scalar_test() -> Result<()> {
+ let input = Arc::new(Int32Array::from(vec![Some(2), None, Some(4)]))
as ArrayRef;
+ let module = ScalarValue::from(10i32);
Review Comment:
Likewise, here a test for null handling might be good
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]