-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support "pre-image" for pruning predicate evaluation #18789
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
Draft
sdf-jkl
wants to merge
40
commits into
apache:main
Choose a base branch
from
sdf-jkl:pre-image-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
de30cb0
create first test
sdf-jkl 052ab95
year_literal_to_type_with_op function
sdf-jkl d9a4253
kinda works
sdf-jkl 83bae02
getting_there
sdf-jkl eec27c1
Merge branch 'apache:main' into pre-image-support
sdf-jkl 1e794c3
taplo format
sdf-jkl 2ec0b9a
add op_swap test
sdf-jkl 630f5c5
Fix comment
sdf-jkl fbcfb97
commented out attempt for inlist support
sdf-jkl 2b54409
restructure the changes
sdf-jkl 3260ee9
Update datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
sdf-jkl cdfc2f5
Merge branch 'main' into pre-image-support
sdf-jkl d011b51
Fix merge error
sdf-jkl cd390df
cargo fmt plus some fixes
sdf-jkl 36bb529
Add sqllogictest
sdf-jkl 7c4dd9c
Add other than year date_part tests
sdf-jkl cdb9cb6
Fix docs
sdf-jkl 57ee667
cargo fmt
sdf-jkl bb50792
Cargo fmt + doc changes
sdf-jkl fa3b31c
Merge branch 'main' into pre-image-support
sdf-jkl 729951b
Rewrite logic
sdf-jkl 8b62a2d
Merge branch 'pre-image-support' of https://github.com/sdf-jkl/datafu…
sdf-jkl ab9b444
support IsDistinctFrom and IsNotDistinctFrom
sdf-jkl 5286626
Update sqllogictests
sdf-jkl 5106049
Remove commented out changes
sdf-jkl 19fafd1
Merge branch 'main' into pre-image-support
sdf-jkl 516e637
Merge branch 'main' into pre-image-support
sdf-jkl 5899a3a
Merge branch 'main' into pre-image-support
sdf-jkl e1c358f
Implementing suggestions
sdf-jkl 63761a1
Merge branch 'pre-image-support' of https://github.com/sdf-jkl/datafu…
sdf-jkl c79e937
fix ci
sdf-jkl 0318c62
Merge branch 'main' of https://github.com/apache/datafusion into pre-…
sdf-jkl 352b3ff
cargo fmt
sdf-jkl 7dbdc00
Move tests to core/optimizer/tests
sdf-jkl 19ba392
Merge branch 'main' of https://github.com/apache/datafusion into pre-…
sdf-jkl 5456976
Merge branch 'main' of https://github.com/apache/datafusion into pre-…
sdf-jkl 114eb50
Merge branch 'main' of https://github.com/apache/datafusion into pre-…
sdf-jkl 130413d
Improve IsDistinctFrom, IsNotDistinctFrom logic and add unit tests fo…
sdf-jkl ae05293
Return sqllogictests + add unit tests
sdf-jkl bc91039
Merge branch 'main' into pre-image-support
sdf-jkl 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -226,6 +226,25 @@ impl ScalarUDF { | |
| self.inner.simplify(args, info) | ||
| } | ||
|
|
||
| /// Return a preimage | ||
| /// | ||
| /// See [`ScalarUDFImpl::preimage`] for more details. | ||
| pub fn preimage( | ||
| &self, | ||
| args: &[Expr], | ||
| lit_expr: &Expr, | ||
| info: &dyn SimplifyInfo, | ||
| ) -> Result<Option<Interval>> { | ||
| self.inner.preimage(args, lit_expr, info) | ||
| } | ||
|
|
||
| /// Return inner column from function args | ||
| /// | ||
| /// See [`ScalarUDFImpl::column_expr`] | ||
| pub fn column_expr(&self, args: &[Expr]) -> Option<Expr> { | ||
| self.inner.column_expr(args) | ||
|
Comment on lines
+244
to
+245
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a little helper method to |
||
| } | ||
|
|
||
| #[deprecated(since = "50.0.0", note = "Use `return_field_from_args` instead.")] | ||
| pub fn is_nullable(&self, args: &[Expr], schema: &dyn ExprSchema) -> bool { | ||
| #[expect(deprecated)] | ||
|
|
@@ -696,6 +715,36 @@ pub trait ScalarUDFImpl: Debug + DynEq + DynHash + Send + Sync { | |
| Ok(ExprSimplifyResult::Original(args)) | ||
| } | ||
|
|
||
| /// Returns the [preimage] for this function and the specified scalar value, if any. | ||
| /// | ||
| /// A preimage is a single contiguous [`Interval`] of values where the function | ||
| /// will always return `lit_value` | ||
| /// | ||
| /// This rewrite is described in the [ClickHouse Paper] and is particularly | ||
| /// useful for simplifying expressions `date_part` or equivalent functions. The | ||
| /// idea is that if you have an expression like `date_part(YEAR, k) = 2024` and you | ||
| /// can find a [preimage] for `date_part(YEAR, k)`, which is the range of dates | ||
| /// covering the entire year of 2024. Thus, you can rewrite the expression to `k | ||
| /// >= '2024-01-01' AND k < '2025-01-01' which is often more optimizable. | ||
| /// | ||
| /// This should only return a preimage if the function takes a single argument | ||
| /// | ||
| /// [ClickHouse Paper]: https://www.vldb.org/pvldb/vol17/p3731-schulze.pdf | ||
| /// [preimage]: https://en.wikipedia.org/wiki/Image_(mathematics)#Inverse_image | ||
| fn preimage( | ||
| &self, | ||
| _args: &[Expr], | ||
| _lit_expr: &Expr, | ||
| _info: &dyn SimplifyInfo, | ||
| ) -> Result<Option<Interval>> { | ||
| Ok(None) | ||
| } | ||
|
|
||
| // Return the inner column expression from this function | ||
| fn column_expr(&self, _args: &[Expr]) -> Option<Expr> { | ||
| None | ||
| } | ||
|
|
||
| /// Returns true if some of this `exprs` subexpressions may not be evaluated | ||
| /// and thus any side effects (like divide by zero) may not be encountered. | ||
| /// | ||
|
|
@@ -926,6 +975,19 @@ impl ScalarUDFImpl for AliasedScalarUDFImpl { | |
| self.inner.simplify(args, info) | ||
| } | ||
|
|
||
| fn preimage( | ||
| &self, | ||
| args: &[Expr], | ||
| lit_expr: &Expr, | ||
| info: &dyn SimplifyInfo, | ||
| ) -> Result<Option<Interval>> { | ||
| self.inner.preimage(args, lit_expr, info) | ||
| } | ||
|
|
||
| fn column_expr(&self, args: &[Expr]) -> Option<Expr> { | ||
| self.inner.column_expr(args) | ||
| } | ||
|
|
||
| fn conditional_arguments<'a>( | ||
| &self, | ||
| args: &'a [Expr], | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.