-
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-22704][SQL] Least and Greatest use less global variables #19899
Conversation
Test build #84490 has finished for PR 19899 at commit
|
Test build #84502 has finished for PR 19899 at commit
|
@cloud-fan @viirya @mgaido91 could you please review this? |
ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull) | ||
ctx.addMutableState(ctx.javaType(dataType), ev.value) | ||
def updateEval(eval: ExprCode): String = { | ||
val isNull = ctx.freshName("isNull") |
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: leastTmpIsNull
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.
greatestTmpIsNull
?
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.
val greatestTmpIsNull = ctx.freshName("greatestTmpIsNull")
$isNull = true; | ||
${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)}; | ||
$codes | ||
boolean ${ev.isNull} = $isNull;""") |
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.
final
ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull) | ||
ctx.addMutableState(ctx.javaType(dataType), ev.value) | ||
def updateEval(eval: ExprCode): String = { | ||
val isNull = ctx.freshName("leastTmpIsNull") |
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.
val leastTmpIsNull = ctx.freshName("leastTmpIsNull")
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.
isNull
, ev.isNull
and eval.isNull
looks too close.
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.
yes, but I think we can stay with ev.isNull
and there is no need for this new variable.
val resultType = ctx.javaType(dataType) | ||
val codes = ctx.splitExpressionsWithCurrentInputs( | ||
expressions = evals, | ||
funcName = "least", |
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.
greatest
Test build #84527 has finished for PR 19899 at commit
|
Test build #84529 has finished for PR 19899 at commit
|
$isNull = true; | ||
${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)}; | ||
$codes | ||
final boolean ${ev.isNull} = $isNull;""") |
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: can we switch to the new string style (with stripMargin...)?
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, good catch
ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull) | ||
ctx.addMutableState(ctx.javaType(dataType), ev.value) | ||
def updateEval(eval: ExprCode): String = { | ||
val isNull = ctx.freshName("greatestTmpIsNull") |
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 there is no need for it and we can use ev.isNull
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.
As I wrote in the description, we would like to make the lifetime of a global variable local.
Sorry for missing addition of this explanation.
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 am not sure about this. Because anyway, if ev.isNull
is a global variable, here the problem would still exist since we are declaring it in the method (line 635). So I don't see how this changes/solves the problem.
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.
IIUC, at line 635 ev.isNull
is declared as local variable.
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.
yes, thus if it is declared as global variable, we still have a global variable with the same name of a local one. Am I missing something?
ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull) | ||
ctx.addMutableState(ctx.javaType(dataType), ev.value) | ||
def updateEval(eval: ExprCode): String = { | ||
val leastTmpIsNull = ctx.freshName("leastTmpIsNull") |
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.
super nit: a convention from your another PR: val tmpIsNull = ctx.freshName("leastTmpIsNull")
${ev.value} = ${ctx.defaultValue(dataType)}; | ||
$codes""") | ||
|${eval.code} | ||
|if (!${eval.isNull} && (${leastTmpIsNull} || |
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 $leastTmpIsNull
ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull) | ||
ctx.addMutableState(ctx.javaType(dataType), ev.value) | ||
def updateEval(eval: ExprCode): String = { | ||
val greatestTmpIsNull = ctx.freshName("greatestTmpIsNull") |
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.
ditto
${ev.value} = ${ctx.defaultValue(dataType)}; | ||
$codes""") | ||
|${eval.code} | ||
|if (!${eval.isNull} && (${greatestTmpIsNull} || |
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.
ditto
LGTM except some minor style comments |
Test build #84547 has finished for PR 19899 at commit
|
Test build #84556 has finished for PR 19899 at commit
|
LGTM |
LGTM, thanks. |
Test build #84560 has finished for PR 19899 at commit
|
thanks, merging to master! |
What changes were proposed in this pull request?
This PR accomplishes the following two items.
Item 1. reduces # of constant pool entries in a Java class. Item 2. ensures that an variable is not passed to arguments in a method split by
CodegenContext.splitExpressions()
, which is addressed by #19865.How was this patch tested?
Added new test into
ArithmeticExpressionSuite