-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-50377][SQL] Allow to evaluate foldable RuntimeReplaceable #48912
Conversation
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
Outdated
Show resolved
Hide resolved
…essions/arithmetic.scala
final override def eval(input: InternalRow = null): Any = { | ||
// For convenience, we allow to evaluate `RuntimeReplaceable` expressions, in case we need to | ||
// get a constant from foldable expression before the query execution starts. | ||
assert(input == null) |
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.
Sorry, could you clarify why do you require null
instead of just bypass input
to replacement.eval()
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 the premise here must be that input == null
, then would it be better to throw a meaningful QueryExecutionError instead of an AssertionError
when input is not null?
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.
Ideally people should never eagerly evaluate a RuntimeReplaceable
, the only case I see is evaluating foldable expressions. I think it's better to only allow it, to make sure that there is no RuntimeReplaceable
leaked to the runtime execution.
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.
I use assert
as this means bug, not a user error.
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.
I use
assert
as this means bug, not a user error.
Got it,thanks
thanks for the review, merging to master! |
What changes were proposed in this pull request?
This is to fix a regression caused by #47143 . The problem is, in some places, we want to get a constant from a foldable expression before the query execution starts. #47143 brings two problems:
UnaryPositive
is no longer aUnaryExpression
, which means it's not foldable anymore even if its child is foldable.UnaryPositive
is no longer evaluable.Lag
is such a place. It may evaluate theinputOffset
parameter eagerly.lag(..., +1)
no longer works after #47143 .Instead of fixing
Lag
, this PR makes two changes and hopefully we can avoid all similar problems:UnaryPositive
extendUnaryExpression
again. We need follow-up PRs to check otherRuntimeReplaceable
expressions and see if they should extendUnaryExpression
orBinaryExpression
, etc.RuntimeReplaceable#eval
so that we can evaluate foldingRuntimeReplaceable
eagerly when needed.Why are the changes needed?
Fix the regression on
lag
and avoid similar issues in the future.Does this PR introduce any user-facing change?
No, the regression is not released yet.
How was this patch tested?
new test
Was this patch authored or co-authored using generative AI tooling?
no