Uh oh!
There was an error while loading. Please reload this page.
feat: Support Binary bitwise shift operators (<< and >>) - #3037
Conversation
a5a06ff to
6449570CompareRight now, DF uses Generic Dialect for Token::ShiftLeftifdialect_of!(self is PostgreSqlDialect) => {Some(BinaryOperator::PGBitwiseShiftLeft)}Token::ShiftRight if dialect_of!(self is PostgreSqlDialect) => {Some(BinaryOperator::PGBitwiseShiftRight)}@alamb what should I do with it? Should I Introduce new methods for Dialect to allow these operators with Generic dialect? Thanks |
alamb
commented
Aug 4, 2022
What about allowing I can make another sql-parser release soon if you need one as well |
| } | ||
| } | ||
| pub(crate) fn bitwise_shift_right(left: ArrayRef, right: ArrayRef) -> Result<ArrayRef> { |
liukun4515
commented
Aug 5, 2022
LGTM, if we can merge the sql-rs first |
ovr
commented
Aug 5, 2022
Looks likes I forget about overflowing here. I think I can use |
4e1dfde to
36aff67Compareovr
commented
Aug 5, 2022
Panic on overflow was fixed in 474ed5a Without error to be similar with PostgreSQL |
alamb
commented
Aug 6, 2022
https://crates.io/crates/sqlparser/0.20.0 is released, FYI |
ovr
commented
Aug 8, 2022
Awaiting #3072 |
alamb
commented
Aug 8, 2022
Is merged 🎉 |
474ed5a to
636be02Compare| @@ -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 { | |||
There was a problem hiding this comment.
I've changed binary_bitwise_array_scalar to pass function as expr to do casting, because wrapping_shr and wrapping_shl requires u32. I tried to do it with let right: $TYPE = scalar.try_into().unwrap(); but I found that it will show a error because it's not possible to cast all numeric types to u32.
There was a problem hiding this comment.
I think it makes sense -- thank you
636be02 to
17fb689Compare17fb689 to
92fa53cCompareCodecov Report
@@ Coverage Diff @@## master #3037 +/- ##
==========================================
- Coverage 85.95% 85.91% -0.04%
==========================================
Files 291 291 Lines 52382 52475 +93 ==========================================
+ Hits 45025 45084 +59 - Misses 7357 7391 +34
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
alamb
left a comment
There was a problem hiding this comment.
This PR is looking pretty good 👍
Please mark it as "ready for review" when it is ready.
Thanks !
ovr
commented
Aug 12, 2022
Marked PR as ready for review ✅ |
| 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)]); |
There was a problem hiding this comment.
There was a problem hiding this comment.
2<<100 =>> 2<<(100%bit_width(i32)) =>> 2 << 4?
There was a problem hiding this comment.
i am surprised that this is rotational shifting
There was a problem hiding this comment.
i am surprised that this is rotational shifting
me too...
| #[test] | ||
| fn bitwise_shift_array_test() -> Result<()> { | ||
| let input = Arc::new(Int32Array::from(vec![Some(2), None, Some(10)])) as ArrayRef; | ||
| let modules = |
There was a problem hiding this comment.
I suggest a test for when the modules is Null (you cover NULL for the input already)
| #[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); |
There was a problem hiding this comment.
Likewise, here a test for null handling might be good
There was a problem hiding this comment.
Instead of doing unit test here, I did a simple SQL test which test the whole pipeline, and I found that DF doesn't handle nulls for bitwise operators.
Fixed in:
| @@ -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 { | |||
There was a problem hiding this comment.
I think it makes sense -- thank you
92fa53c to
624e8b3Compare| use arrow::datatypes::DataType::*; | ||
| if !is_numeric(left_type) || !is_numeric(right_type) { | ||
| if !both_numeric_or_null_and_numeric(left_type, right_type) { |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Jiayu Liu <Jimexist@users.noreply.github.com>
andygrove
commented
Aug 15, 2022
Can we update the user guide to show this new functionality? This can be a follow-on issue. |
I didn't find any place where I should update the documentation, as I can see there is a small comment about binary expressions, but it doesn't include all binary expressions.
I updated the description on this PR to reference #1619 |
ursabot
commented
Aug 15, 2022
Benchmark runs are scheduled for baseline = 5ddad47 and contender = ee55d89. ee55d89 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |


Which issue does this PR close?
This PR introduces support for binary bitwise shift operators like
>>and<<.Refs #1619
Are there any user-facing changes?
It's new functionality, and there are no breaking changes.
Thanks!