-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-22550][SQL] Fix 64KB JVM bytecode limit problem with elt #19778
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,22 +224,55 @@ case class Elt(children: Seq[Expression]) | |
| override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
| val index = indexExpr.genCode(ctx) | ||
| val strings = stringExprs.map(_.genCode(ctx)) | ||
| val indexVal = ctx.freshName("index") | ||
| val stringVal = ctx.freshName("stringVal") | ||
| val assignStringValue = strings.zipWithIndex.map { case (eval, index) => | ||
| s""" | ||
| case ${index + 1}: | ||
| ${ev.value} = ${eval.isNull} ? null : ${eval.value}; | ||
| ${eval.code} | ||
| $stringVal = ${eval.isNull} ? null : ${eval.value}; | ||
| break; | ||
| """ | ||
| }.mkString("\n") | ||
| val indexVal = ctx.freshName("index") | ||
| val stringArray = ctx.freshName("strings"); | ||
| } | ||
|
|
||
| ev.copy(index.code + "\n" + strings.map(_.code).mkString("\n") + s""" | ||
| final int $indexVal = ${index.value}; | ||
| UTF8String ${ev.value} = null; | ||
| switch ($indexVal) { | ||
| $assignStringValue | ||
| val cases = ctx.splitCodes(assignStringValue) | ||
| val codes = if (cases.length == 1) { | ||
| s""" | ||
| UTF8String $stringVal = null; | ||
| switch ($indexVal) { | ||
| ${cases.head} | ||
| } | ||
| """ | ||
| } else { | ||
| var fullFuncName = "" | ||
| cases.reverse.zipWithIndex.map { case (s, index) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to make it more imperative: |
||
| val prevFunc = if (index == 0) { | ||
| "null" | ||
| } else { | ||
| s"$fullFuncName(${ctx.INPUT_ROW}, $indexVal)" | ||
| } | ||
| val funcName = ctx.freshName("eltFunc") | ||
| val funcBody = s""" | ||
| private UTF8String $funcName(InternalRow ${ctx.INPUT_ROW}, int $indexVal) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this splitting doesn't prevent the case in wholestage codegen?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah good catch! we should fix it with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proposes a fix in #19964. |
||
| UTF8String $stringVal = null; | ||
| switch ($indexVal) { | ||
| $s | ||
| default: | ||
| return $prevFunc; | ||
| } | ||
| return $stringVal; | ||
| } | ||
| """ | ||
| fullFuncName = ctx.addNewFunction(funcName, funcBody) | ||
| } | ||
| s"UTF8String $stringVal = $fullFuncName(${ctx.INPUT_ROW}, ${indexVal});" | ||
| } | ||
|
|
||
| ev.copy(index.code + "\n" + | ||
| s""" | ||
| final int $indexVal = ${index.value}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| $codes | ||
| UTF8String ${ev.value} = $stringVal; | ||
| final boolean ${ev.isNull} = ${ev.value} == 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.
actually
splitis not accurate here, how aboutgroupCodes?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: private. We also need to write a comment.
How about
buildCodeBlocks?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.
Sure, but it is not
private. It is used instringExpressions.