Skip to content

[SPARK-22682][SQL] HashExpression does not need to create global variables - #19878

Closed
cloud-fan wants to merge 1 commit into
apache:masterfrom
cloud-fan:minor
Closed

[SPARK-22682][SQL] HashExpression does not need to create global variables#19878
cloud-fan wants to merge 1 commit into
apache:masterfrom
cloud-fan:minor

Conversation

@cloud-fan

Copy link
Copy Markdown
Contributor

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

@cloud-fan

Copy link
Copy Markdown
ContributorAuthor

}

val hashResultType = ctx.javaType(dataType)
val codes = if (ctx.INPUT_ROW == null || ctx.currentVars != null) {

Copy link
Copy Markdown
ContributorAuthor

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.

Copy link
Copy Markdown
Contributor

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

@gatorsmilegatorsmileDec 4, 2017

Copy link
Copy Markdown
Member

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(

Copy link
Copy Markdown
ContributorAuthor

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.

val fieldsHash = fields.zipWithIndex.map { case (field, index) =>
nullSafeElementHash(input, index.toString, field.nullable, field.dataType, result, ctx)
}
val hashResultType = ctx.javaType(dataType)

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
ContributorAuthor

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

@mgaido91

Copy link
Copy Markdown
Contributor

left only one very minor comment, it LGTM

@SparkQA

Copy link
Copy Markdown

Test build #84431 has finished for PR 19878 at commit 0e9998e.

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

ev.copy(code =
s"""
|${ctx.JAVA_INT} ${ev.value} = $seed;
|${ctx.JAVA_INT} $childHash = 0;

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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(

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
ContributorAuthor

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.

@viirya

Copy link
Copy Markdown
Member

LGTM

@cloud-fan

Copy link
Copy Markdown
ContributorAuthor

thanks, merging to master!

@asfgitasfgit closed this in a8af4daDec 5, 2017
Sign up for freeto 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

@cloud-fan@mgaido91@SparkQA@viirya@gatorsmile