-
Notifications
You must be signed in to change notification settings - Fork 525
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
refactor(expr): prevent implicit array-compaction in Expression::eval #3523
Conversation
Signed-off-by: TennyZhuang <zty0826@gmail.com>
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.
LGTM for rest
src/expr/src/expr/mod.rs
Outdated
@@ -56,6 +56,14 @@ pub type ExpressionRef = Arc<dyn Expression>; | |||
pub trait Expression: std::fmt::Debug + Sync + Send { | |||
fn return_type(&self) -> DataType; | |||
|
|||
fn wrapping_eval(&self, input: &DataChunk) -> Result<ArrayRef> { |
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 add some rustdoc
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.
+1
src/expr/src/expr/mod.rs
Outdated
@@ -128,7 +136,7 @@ impl RowExpression { | |||
|
|||
pub fn eval(&mut self, row: &Row, data_types: &[DataType]) -> Result<ArrayRef> { | |||
let input = DataChunk::from_rows(slice::from_ref(row), data_types)?; | |||
self.expr.eval(&input) | |||
self.expr.wrapping_eval(&input) |
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 eval()
useless now?
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.
eval is the implementation, and wrapping_eval add some common checks.
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.
wrapping
sounds like a numeric overflow wrapping to me. 😢 Name it checked_eval
or something?
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.
wrapping is just eval with a wrapper :)
Currently we do check here, but I'm thinking about something else, such as tracing span, and the check may also be updated to debug_assert! if we have some benchmarks.
src/expr/src/expr/mod.rs
Outdated
@@ -128,7 +136,7 @@ impl RowExpression { | |||
|
|||
pub fn eval(&mut self, row: &Row, data_types: &[DataType]) -> Result<ArrayRef> { | |||
let input = DataChunk::from_rows(slice::from_ref(row), data_types)?; | |||
self.expr.eval(&input) | |||
self.expr.wrapping_eval(&input) |
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.
wrapping
sounds like a numeric overflow wrapping to me. 😢 Name it checked_eval
or something?
src/expr/src/expr/mod.rs
Outdated
@@ -56,6 +56,14 @@ pub type ExpressionRef = Arc<dyn Expression>; | |||
pub trait Expression: std::fmt::Debug + Sync + Send { | |||
fn return_type(&self) -> DataType; | |||
|
|||
fn wrapping_eval(&self, input: &DataChunk) -> Result<ArrayRef> { |
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.
+1
Signed-off-by: TennyZhuang <zty0826@gmail.com>
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.
Generally lgtm, except that wrapping_eval
is a confusing name.
fn wrapping_eval(&self, input: &DataChunk) -> Result<ArrayRef> { | ||
let res = self.eval(input)?; | ||
|
||
assert_eq!(res.len(), input.capacity()); |
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.
off topic: another useful check would be that array variant (ArrayImpl::Int32
) matches expected return type (DataType::Int32
).
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Codecov Report
@@ Coverage Diff @@
## main #3523 +/- ##
==========================================
- Coverage 74.45% 74.45% -0.01%
==========================================
Files 770 770
Lines 108455 108517 +62
==========================================
+ Hits 80750 80792 +42
- Misses 27705 27725 +20
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
…#3523) * refactor(expr): prevent implicit array-compaction in Expression::eval Signed-off-by: TennyZhuang <zty0826@gmail.com> * address comment Signed-off-by: TennyZhuang <zty0826@gmail.com> * add comments Signed-off-by: TennyZhuang <zty0826@gmail.com> * rename to eval_checked Signed-off-by: TennyZhuang <zty0826@gmail.com> * fix test Signed-off-by: TennyZhuang <zty0826@gmail.com> * fix clippy Signed-off-by: Bugen Zhao <i@bugenzhao.com> Co-authored-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: TennyZhuang zty0826@gmail.com
I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.
What's changed and what's your intention?
PLEASE DO NOT LEAVE THIS EMPTY !!!
As title
It's still error-prone, but I can't find a better solution now.
Checklist
./risedev check
(or alias,./risedev c
)Refer to a related PR or issue link (optional)