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

feat: Support NOT and column expressions in eval_sql_where #653

Merged
merged 4 commits into from
Jan 22, 2025

Conversation

scovich
Copy link
Collaborator

@scovich scovich commented Jan 18, 2025

What changes are proposed in this pull request?

The first attempt at generalizing SQL was incomplete, supporting only AND/OR and binary comparisons. We can also support NULL literal expressions, boolean column expressions and NOT, so add them.

How was this change tested?

Adjusted existing unit tests for the new support (they previously expected it to not work)

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

Attention: Patch coverage is 72.41379% with 16 lines in your changes missing coverage. Please review.

Project coverage is 84.01%. Comparing base (a4009a2) to head (d16697e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
kernel/src/predicates/tests.rs 30.00% 0 Missing and 14 partials ⚠️
...nel/src/predicates/parquet_stats_skipping/tests.rs 0.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #653      +/-   ##
==========================================
- Coverage   84.02%   84.01%   -0.01%     
==========================================
  Files          75       75              
  Lines       17075    17097      +22     
  Branches    17075    17097      +22     
==========================================
+ Hits        14347    14364      +17     
+ Misses       2044     2043       -1     
- Partials      684      690       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

];
self.finish_eval_variadic(VariadicOperator::And, exprs, false)
}
_ => self.eval_expr(filter, false),
// NOTE: It's unsafe to process other expressions like DISTINCT, IS NULL, and literals
Copy link
Collaborator

Choose a reason for hiding this comment

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

this warning is a good addition 👌

Copy link
Collaborator

@zachschuermann zachschuermann left a comment

Choose a reason for hiding this comment

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

lgtm couple nits

kernel/src/predicates/mod.rs Outdated Show resolved Hide resolved
kernel/src/predicates/mod.rs Outdated Show resolved Hide resolved
];
self.finish_eval_variadic(VariadicOperator::And, exprs, false)
}
_ => self.eval_expr(filter, false),
// NOTE: It's unsafe to process other expressions like DISTINCT, IS NULL, and literals
// with null-safe semantics, so just process them normally.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can we add some of the context you sent me on slack @scovich 😆

e.g. the example of FALSE dominating AND and giving unconditional (incorrect) skipping?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The case I worried about was:

AND(NULL, ...)
= AND(NULL IS NOT NULL AND NULL, ...)
= AND(FALSE AND NULL, ...)
= AND(FALSE, ...)
= FALSE

However, from SQL perspective, that behavior is actually correct -- the (unmodified) filter can never evaluate to TRUE, so such rows will always be dropped. SQL semantics just changes the NULL to a FALSE to allow data skipping.

Based on this, I updated the PR to cover NULL literals after all.

@scovich
Copy link
Collaborator Author

scovich commented Jan 22, 2025

I'm getting 404 on codecov links (???) but from previous experience the low coverage is due to unit tests that don't fail and therefore don't exercise their failure messages.

@scovich scovich merged commit bf7e212 into delta-io:main Jan 22, 2025
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants