-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-46707][SQL] Added throwable field to expressions to improve predicate pushdown #44716
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
Conversation
8f86617 to
afd0d87
Compare
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.
Can we leverage NoThrow trait?
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.
the problem with NoThrow is that it doesn't mark that many expressions right now (i.e. if we only push down NoThrow expressions then we would be not pushing down most things). we want the opposite here (marking only certain expressions not to push down). defining it this way also allows us to be more precise with defining what is throwable, compared to just setting it for the class
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.
These two are similar but be conservative in two opposite directions. Filter pushdown is a very important feature and we don't want to suddenly disable it for many predicates. We only mark sequence as throwable for now.
NoThrow was added for a new optimization and only a few expressions are marked as NoThrow that can be optimized.
Since runtime error is rare, I think the current solution is better to produce more optimized plans for most cases.
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.
If it's rare, why do we add a property to Expression?
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.
Because it's indeed an expression property. NoThrow is not the right way to add properties as the caller side needs to do recursion: https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala#L53-L59 , which is not good for code reuse (you need to call a util function)
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.
Should probably remove NoThrow then ... I approved it for now.
afd0d87 to
f19267a
Compare
|
I'm a bit confused. Why not pushdown predicate through join will not throw exception ? |
|
@beliefer if we have a plan like it is possible to have a scenario where:
|
|
thanks, merging to master! |
|
@kelvinjian-db I guess it causes an exception if the join key is not related to |
What changes were proposed in this pull request?
This PR adds the field
throwabletoExpression. If an expression is marked as throwable, we will avoid pushing filters containing these expressions through joins, filters, and aggregations (i.e. operators that filter input).Why are the changes needed?
For predicate pushdown, currently it is possible that we push down a filter that ends up being evaluated on more rows than before it was pushed down (e.g. if we push the filter through a selective join). In this case, it is possible that we now evaluate the filter on a row that will cause a runtime error to be thrown, when prior to pushing this would not have happened.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added UTs.
Was this patch authored or co-authored using generative AI tooling?
No.