-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-22682][SQL] HashExpression does not need to create global variables #19878
Conversation
} | ||
|
||
val hashResultType = ctx.javaType(dataType) | ||
val codes = if (ctx.INPUT_ROW == null || ctx.currentVars != 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.
This pattern appears many times in the code base, we may need to create a ctx.splitExpressionsWithCurrentInput
for it later.
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 think @kiszk is doing this
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.
That one has been merged, but this one is still different.
childResult, ctx)} | ||
$localResult = (31 * $localResult) + $childResult; | ||
""" | ||
}.mkString( |
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.
We forgot to split the code for computing hive hash of struct, it's fixed now.
nullSafeElementHash(input, index.toString, field.nullable, field.dataType, result, ctx) | ||
} | ||
val hashResultType = ctx.javaType(dataType) |
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.
nit: this is done also in line 281. Can we do this only once? maybe with a lazy val
?
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.
ctx
is only available inside doGenCode
left only one very minor comment, it LGTM |
Test build #84431 has finished for PR 19878 at commit
|
ev.copy(code = | ||
s""" | ||
|${ctx.JAVA_INT} ${ev.value} = $seed; | ||
|${ctx.JAVA_INT} $childHash = 0; |
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.
nit: childHash
is only needed to declare here when we don't split functions.
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.
nvm, splitExpressions
could possibly not split expressions if only one block.
""".stripMargin | ||
} | ||
|
||
s"${ctx.JAVA_INT} $childResult = 0;\n" + ctx.splitExpressions( |
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.
No need to check ctx.INPUT_ROW == null || ctx.currentVars != null
here?
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.
Yea, the input here is a row that may be produced by row.getStruct
instead of ctx.INPUT_ROW
, so we don't need this check as the input won't be ctx.currentVars
.
LGTM |
thanks, merging to master! |
What changes were proposed in this pull request?
It turns out that
HashExpression
can pass around some values via parameter when splitting codes into methods, to save some global variable slots.This can also prevent a weird case that global variable appears in parameter list, which is discovered by #19865
How was this patch tested?
existing tests