-
Notifications
You must be signed in to change notification settings - Fork 600
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
feat(expr): Implementation for bitwise operation #2884
Merged
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
43baed2
Add bitwise_op.rs and implement << and >>
marvenlee2486 8d81e88
Add ExprType and Do binding of BinaryOperator to ExprType
marvenlee2486 1137e7f
ModifeModified expr and frontend
marvenlee2486 b330586
Working for >> and <<
marvenlee2486 b1b3095
Trying to add bitand but facing problem
marvenlee2486 4a82382
Done implementation for bitwise and or XOR(#), TODO ~ and Unit Test a…
marvenlee2486 b8893b9
Edit Bitwise not But still have server closed unexpected error
marvenlee2486 748ae00
Bitwise not done implemetation. TODO Testing
marvenlee2486 00662e1
Done Unit testing, and done code e2e test
marvenlee2486 3fcbe92
Done Unit testing, and done code e2e test
marvenlee2486 93c3b23
last commit
marvenlee2486 a2011f8
Final commit
marvenlee2486 3db27fd
Edit minor changes
marvenlee2486 eeadf9e
Final commit
marvenlee2486 cfd560c
return the error
marvenlee2486 b402de0
Revert
marvenlee2486 d43565b
Change to Upper Snake Case
marvenlee2486 a7f6405
Remove wRemove extra white space at the end of the code
marvenlee2486 41b0d0d
Remove wadd extra ace at the end of the code
marvenlee2486 87296fd
Modifed e2e tests
marvenlee2486 b59ac4d
Delete Bitwise e2e
marvenlee2486 3eb7175
Change e2e bitwise from select to values
marvenlee2486 90444b8
Revert "Change e2e bitwise from select to values"
marvenlee2486 fab8764
revision
lmatz 14bb70e
Edit error
marvenlee2486 b8e3a13
Resolve all comments except 'no overflow' comment
marvenlee2486 78a54c3
Delete the additional test and solve formatting issues
marvenlee2486 5398d8a
Resolve test error
marvenlee2486 c66ca60
OTrucated to zero
marvenlee2486 a3c3cb3
Change error in test
marvenlee2486 ad7dda7
Change error in test
marvenlee2486 91095a3
Edit Test error
marvenlee2486 0b1cfb3
Edit test error
marvenlee2486 ec4c0e0
Change format
marvenlee2486 70a5d8e
Resolve compilation error
marvenlee2486 b773ad7
Resolve error
marvenlee2486 0d8e71f
Resolve error
marvenlee2486 53db214
Resolve test error
marvenlee2486 c87bbe0
Resolve test error
marvenlee2486 7e771f5
Resolve type_inference error
marvenlee2486 4a422c8
Resolve format error
marvenlee2486 1bc00ef
Resolve format error
marvenlee2486 0e68cee
Resolve format error
marvenlee2486 b7f0d46
Resolve test error
marvenlee2486 289d30c
Resolve error
marvenlee2486 05ba239
Resolve license fail
marvenlee2486 541c447
Edit the lose edition
marvenlee2486 5926d4e
Resolve error due to merge conflict resolve error
marvenlee2486 05be5d7
Revert to having overflow error
marvenlee2486 f3b9898
Merge branch 'main' into zongyu/bitwise_operation
marvenlee2486 45962dc
Remove autogenerated unwanted file
marvenlee2486 a157eb9
Resolve some comments - Duplication, Docs on Code
marvenlee2486 6f73499
Resolves all other comments
marvenlee2486 eb52467
Delete unwanted import
marvenlee2486 9ba0050
Merge branch 'main' into zongyu/bitwise_operation
marvenlee2486 30637e2
Resolve merge error
marvenlee2486 481e578
Format error
marvenlee2486 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
query I | ||
values(3&5); | ||
---- | ||
1 | ||
|
||
query I | ||
values(3|5); | ||
---- | ||
7 | ||
|
||
query I | ||
values(3#5); | ||
---- | ||
6 | ||
|
||
query I | ||
values(1<<2); | ||
---- | ||
4 | ||
|
||
query I | ||
values(4>>2); | ||
---- | ||
1 | ||
|
||
query I | ||
values(~1); | ||
---- | ||
-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2022 Singularity Data | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
use std::any::type_name; | ||
use std::convert::TryInto; | ||
use std::fmt::Debug; | ||
use std::ops::{BitAnd, BitOr, BitXor, Not}; | ||
|
||
use num_traits::{CheckedShl, CheckedShr}; | ||
use risingwave_common::error::ErrorCode::{InternalError, NumericValueOutOfRange}; | ||
use risingwave_common::error::{Result, RwError}; | ||
|
||
use crate::vector_op::arithmetic_op::general_atm; | ||
|
||
// Conscious decision for shl and shr is made here to diverge from PostgreSQL. | ||
// If overflow happens, instead of truncated to zero, we return overflow error as this is | ||
// undefined behaviour. If the RHS is negative, instead of having an unexpected answer, we return an | ||
// error. If PG had clearly defined behavior rather than relying on UB of C, we would follow it even | ||
// when it is different from rust std. | ||
#[inline(always)] | ||
pub fn general_shl<T1, T2>(l: T1, r: T2) -> Result<T1> | ||
where | ||
T1: CheckedShl + Debug, | ||
T2: TryInto<u32> + Debug, | ||
{ | ||
general_shift(l, r, |a, b| { | ||
a.checked_shl(b) | ||
.ok_or_else(|| RwError::from(NumericValueOutOfRange)) | ||
}) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn general_shr<T1, T2>(l: T1, r: T2) -> Result<T1> | ||
where | ||
T1: CheckedShr + Debug, | ||
T2: TryInto<u32> + Debug, | ||
{ | ||
general_shift(l, r, |a, b| { | ||
a.checked_shr(b) | ||
.ok_or_else(|| RwError::from(NumericValueOutOfRange)) | ||
}) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn general_shift<T1, T2, F>(l: T1, r: T2, atm: F) -> Result<T1> | ||
where | ||
T1: Debug, | ||
T2: TryInto<u32> + Debug, | ||
F: FnOnce(T1, u32) -> Result<T1>, | ||
{ | ||
// TODO: We need to improve the error message | ||
let r: u32 = r.try_into().map_err(|_| { | ||
RwError::from(InternalError(format!( | ||
"Can't convert {} to {}", | ||
type_name::<T2>(), | ||
type_name::<u32>() | ||
))) | ||
})?; | ||
atm(l, r) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn general_bitand<T1, T2, T3>(l: T1, r: T2) -> Result<T3> | ||
where | ||
T1: TryInto<T3> + Debug, | ||
T2: TryInto<T3> + Debug, | ||
T3: BitAnd<Output = T3>, | ||
{ | ||
general_atm(l, r, |a, b| Ok(a.bitand(b))) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn general_bitor<T1, T2, T3>(l: T1, r: T2) -> Result<T3> | ||
where | ||
T1: TryInto<T3> + Debug, | ||
T2: TryInto<T3> + Debug, | ||
T3: BitOr<Output = T3>, | ||
{ | ||
general_atm(l, r, |a, b| Ok(a.bitor(b))) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn general_bitxor<T1, T2, T3>(l: T1, r: T2) -> Result<T3> | ||
where | ||
T1: TryInto<T3> + Debug, | ||
T2: TryInto<T3> + Debug, | ||
T3: BitXor<Output = T3>, | ||
{ | ||
general_atm(l, r, |a, b| Ok(a.bitxor(b))) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn general_bitnot<T1: Not<Output = T1>>(expr: T1) -> Result<T1> { | ||
Ok(expr.not()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please reformat it,
cargo fmt --all
seems not work on code in macro.