Skip to content
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

Merged
merged 8 commits into from
Jun 29, 2022

Conversation

TennyZhuang
Copy link
Collaborator

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

  • I have written necessary docs and comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Refer to a related PR or issue link (optional)

Signed-off-by: TennyZhuang <zty0826@gmail.com>
@TennyZhuang TennyZhuang marked this pull request as ready for review June 28, 2022 09:26
Copy link
Contributor

@fuyufjh fuyufjh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for rest

@@ -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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some rustdoc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is eval() useless now?

Copy link
Collaborator Author

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.

Copy link
Member

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?

Copy link
Collaborator Author

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.

@@ -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)
Copy link
Member

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/common/src/array/data_chunk_iter.rs Show resolved Hide resolved
src/expr/src/expr/expr_case.rs Outdated Show resolved Hide resolved
src/expr/src/expr/expr_nested_construct.rs Outdated Show resolved Hide resolved
@@ -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> {
Copy link
Member

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

@xiangjinwu xiangjinwu left a 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());
Copy link
Contributor

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: TennyZhuang <zty0826@gmail.com>
@TennyZhuang TennyZhuang added the mergify/can-merge Indicates that the PR can be added to the merge queue label Jun 29, 2022
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
@codecov
Copy link

codecov bot commented Jun 29, 2022

Codecov Report

Merging #3523 (6276ac9) into main (e40327b) will decrease coverage by 0.00%.
The diff coverage is 77.85%.

@@            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     
Flag Coverage Δ
rust 74.45% <77.85%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/common/src/array/bool_array.rs 91.80% <0.00%> (-1.54%) ⬇️
src/common/src/array/decimal_array.rs 89.35% <0.00%> (-1.26%) ⬇️
src/common/src/array/list_array.rs 88.75% <0.00%> (-0.54%) ⬇️
src/common/src/array/mod.rs 72.17% <0.00%> (-0.85%) ⬇️
src/common/src/array/primitive_array.rs 88.50% <0.00%> (-1.35%) ⬇️
src/common/src/array/struct_array.rs 77.53% <0.00%> (-0.65%) ⬇️
src/common/src/array/utf8_array.rs 92.51% <0.00%> (-0.96%) ⬇️
src/expr/src/expr/template.rs 68.04% <50.00%> (-0.71%) ⬇️
src/expr/src/expr/expr_literal.rs 97.95% <66.66%> (ø)
src/expr/src/expr/expr_nested_construct.rs 79.24% <66.66%> (+1.26%) ⬆️
... and 20 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@mergify mergify bot merged commit c4c7ab6 into main Jun 29, 2022
@mergify mergify bot deleted the refactor/expr-no-implicit-compact branch June 29, 2022 10:06
huangjw806 pushed a commit that referenced this pull request Jul 5, 2022
…#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergify/can-merge Indicates that the PR can be added to the merge queue type/refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants