Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

kiszk
Copy link
Member

@kiszk kiszk commented Dec 5, 2017

What changes were proposed in this pull request?

This PR accomplishes the following two items.

  1. Reduce # of global variables from two to one
  2. Make lifetime of global variable local within an operation

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

@SparkQA
Copy link

SparkQA commented Dec 5, 2017

Test build #84490 has finished for PR 19899 at commit 544d23d.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 5, 2017

Test build #84502 has finished for PR 19899 at commit d322931.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@kiszk
Copy link
Member Author

kiszk commented Dec 6, 2017

@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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: leastTmpIsNull

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

greatestTmpIsNull?

Copy link
Member

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;""")
Copy link
Contributor

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")
Copy link
Member

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")

Copy link
Member

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.

Copy link
Contributor

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

greatest

@SparkQA
Copy link

SparkQA commented Dec 6, 2017

Test build #84527 has finished for PR 19899 at commit facaf1c.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 6, 2017

Test build #84529 has finished for PR 19899 at commit d467192.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

$isNull = true;
${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};
$codes
final boolean ${ev.isNull} = $isNull;""")
Copy link
Contributor

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...)?

Copy link
Member Author

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")
Copy link
Contributor

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

Copy link
Member Author

@kiszk kiszk Dec 6, 2017

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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")
Copy link
Contributor

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} ||
Copy link
Contributor

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")
Copy link
Contributor

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} ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@cloud-fan
Copy link
Contributor

LGTM except some minor style comments

@SparkQA
Copy link

SparkQA commented Dec 6, 2017

Test build #84547 has finished for PR 19899 at commit 47fcdc2.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Dec 6, 2017

Test build #84556 has finished for PR 19899 at commit e5aa90e.

  • This patch fails to build.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

LGTM

@mgaido91
Copy link
Contributor

mgaido91 commented Dec 6, 2017

LGTM, thanks.

@SparkQA
Copy link

SparkQA commented Dec 6, 2017

Test build #84560 has finished for PR 19899 at commit e1ed6c1.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@asfgit asfgit closed this in 813c0f9 Dec 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants