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

chore(pruning): Support IS NOT NULL predicates in PruningPredicate #9208

Merged

Conversation

appletreeisyellow
Copy link
Contributor

@appletreeisyellow appletreeisyellow commented Feb 13, 2024

Which issue does this PR close?

Help with #9171 and #7869

Rationale for this change

PruningPredicate rewrites the original predicate into an expression that references min/max/null_count values of each column in the original predicate

Currently, IS NOT NULL is not supported, which means the rewritten predicate is ALWAYS TRUE, e.g.:

Original Predicate Rewritten Predicate
x IS NOT NULL true

See the code below, phys_expr::IsNotNullExpr is not listed/supported:

https://github.com/apache/arrow-datafusion/blob/292865e38cba1275a0f863230d816ee0e08c1318/datafusion/core/src/physical_optimizer/pruning.rs#L1139-L1140

What changes are included in this PR?

Support IS NOT NULL predicate rewrite, e.g.:

Original Predicate Rewritten Predicate
x IS NOT NULL x_null_count = 0

Are these changes tested?

Yes

Are there any user-facing changes?

No API change. User will experience performance improvements on queries that include IS NOT NULL predicates

@github-actions github-actions bot added the core Core DataFusion crate label Feb 13, 2024
@appletreeisyellow appletreeisyellow marked this pull request as ready for review February 13, 2024 01:22
@alamb alamb changed the title chore(pruning): support is_not_null() predicate rewrite in PruningPredicate chore(pruning): Support IS NOT NULL predicates in PruningPredicate Feb 13, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @appletreeisyellow -- this looks great. The PR description is clear and the code is 👍

Can you please one more test of this logic integrated into the overall row group pruning logic (to make sure it works in the context of a predicate). I think you can follow the model of these tests for IS NULL:

https://github.com/apache/arrow-datafusion/blob/2615d1bd81409b9ecc3e9a4683733c1d60992aa9/datafusion/core/src/datasource/physical_plan/parquet/row_groups.rs#L627-L687

cc @viirya who I think contributed the original IS NULL rewrite

@appletreeisyellow appletreeisyellow force-pushed the chunchun/pruning-predicate-test-is-null branch from 60ea827 to 5040cf8 Compare February 13, 2024 15:36
Comment on lines -629 to +636
// int > 1 and IsNull(bool) => c1_max > 1 and bool_null_count > 0
// c1 > 15 and IsNull(c2) => c1_max > 15 and c2_null_count > 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update comment to reflect the examples given in the test

Copy link
Member

Choose a reason for hiding this comment

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

👍 This reads more smoothly.

Comment on lines -629 to +636
// int > 1 and IsNull(bool) => c1_max > 1 and bool_null_count > 0
// c1 > 15 and IsNull(c2) => c1_max > 15 and c2_null_count > 0
Copy link
Member

Choose a reason for hiding this comment

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

👍 This reads more smoothly.

appletreeisyellow and others added 2 commits February 13, 2024 11:08
Co-authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Co-authored-by: Liang-Chi Hsieh <viirya@gmail.com>
@appletreeisyellow
Copy link
Contributor Author

Can you please one more test of this logic integrated into the overall row group pruning logic (to make sure it works in the context of a predicate). I think you can follow the model of these tests for IS NULL:

@alamb I added one more test into the row group pruning logic in 5040cf8

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks great - thank you @appletreeisyellow and @viirya

@appletreeisyellow
Copy link
Contributor Author

Thank you @alamb and @viirya for the review!

@alamb alamb merged commit cc139c9 into apache:main Feb 14, 2024
23 checks passed
@appletreeisyellow appletreeisyellow deleted the chunchun/pruning-predicate-test-is-null branch February 14, 2024 15:30
@alamb
Copy link
Contributor

alamb commented Feb 14, 2024

I believe this PR has a logic bug that we did not catch in code review: #9230

alamb pushed a commit that referenced this pull request Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants