-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-22498][SQL] Fix 64KB JVM bytecode limit problem with concat #19728
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 1 commit
bc97d41
0ed8d16
366f721
6fdb451
e6b73ab
cd20410
e668b98
555575e
22019b1
b9ca4ff
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 |
|---|---|---|
|
|
@@ -63,15 +63,26 @@ case class Concat(children: Seq[Expression]) extends Expression with ImplicitCas | |
|
|
||
| override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
| val evals = children.map(_.genCode(ctx)) | ||
| val inputs = evals.map { eval => | ||
| s"${eval.isNull} ? null : ${eval.value}" | ||
| }.mkString(", ") | ||
| ev.copy(evals.map(_.code).mkString("\n") + s""" | ||
| boolean ${ev.isNull} = false; | ||
| UTF8String ${ev.value} = UTF8String.concat($inputs); | ||
| if (${ev.value} == null) { | ||
| ${ev.isNull} = true; | ||
| val argNums = evals.length | ||
| val args = ctx.freshName("argLen") | ||
|
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. argLen? I think it's not length of args? |
||
| ctx.addMutableState("UTF8String[]", args, "") | ||
|
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 think we can avoid defining this as a global variable, what do you think? |
||
|
|
||
| val inputs = evals.zipWithIndex.map { case (eval, index) => | ||
| if (eval.isNull != "true") { | ||
|
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. If
Member
Author
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. If
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. please do not mix in optimizations with bug fix
Member
Author
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 see. I will remove this. |
||
| s""" | ||
| ${eval.code} | ||
| $args[$index] = ${eval.value}; | ||
|
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. If
Member
Author
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. good catch |
||
| """ | ||
| } else { | ||
| "" | ||
| } | ||
| } | ||
| val codes = ctx.splitExpressions(ctx.INPUT_ROW, inputs) | ||
| ev.copy(s""" | ||
| $args = new UTF8String[$argNums]; | ||
| $codes | ||
| UTF8String ${ev.value} = UTF8String.concat($args); | ||
| boolean ${ev.isNull} = ${ev.value} == null; | ||
| """) | ||
| } | ||
| } | ||
|
|
@@ -126,18 +137,34 @@ case class ConcatWs(children: Seq[Expression]) | |
| // All children are strings. In that case we can construct a fixed size array. | ||
| val evals = children.map(_.genCode(ctx)) | ||
|
|
||
| val inputs = evals.map { eval => | ||
| s"${eval.isNull} ? (UTF8String) null : ${eval.value}" | ||
| }.mkString(", ") | ||
| val argNums = evals.length | ||
|
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. this should be
Member
Author
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 am sorry that I cannot understand your suggestion.
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. no, I am saying the opposite. Let's consider an example, maybe I better can explain what I mean in this way. Let's assume that we are running I think that in this way the code would be much clearer (other than fixing this little bug).
Member
Author
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. Thank you for your kindly explanation. I totally agree with you. |
||
| val args = ctx.freshName("argLen") | ||
| ctx.addMutableState("UTF8String[]", args, "") | ||
|
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. this also can be kept method local, IMHO |
||
|
|
||
| ev.copy(evals.map(_.code).mkString("\n") + s""" | ||
| UTF8String ${ev.value} = UTF8String.concatWs($inputs); | ||
| val inputs = evals.tail.zipWithIndex.map { case (eval, index) => | ||
| if (eval.isNull != "true") { | ||
|
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. |
||
| s""" | ||
| ${eval.code} | ||
|
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: in this and the next 4 lines an indentation space is missing if I am not wrong.
Member
Author
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. good catch |
||
| $args[$index] = ${eval.value}; | ||
|
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. |
||
| """ | ||
| } else { | ||
| "" | ||
| } | ||
| } | ||
| val codes = s"${evals.head.code}\n" + ctx.splitExpressions(ctx.INPUT_ROW, inputs) | ||
| ev.copy(s""" | ||
| $args = new UTF8String[$argNums]; | ||
| $codes | ||
| UTF8String ${ev.value} = UTF8String.concatWs(${evals.head.value}, $args); | ||
| boolean ${ev.isNull} = ${ev.value} == null; | ||
| """) | ||
| } else { | ||
| val array = ctx.freshName("array") | ||
| ctx.addMutableState("UTF8String[]", array, "") | ||
| val varargNum = ctx.freshName("varargNum") | ||
| ctx.addMutableState("int", varargNum, "") | ||
| val idxInVararg = ctx.freshName("idxInVararg") | ||
| ctx.addMutableState("int", idxInVararg, "") | ||
|
|
||
| val evals = children.map(_.genCode(ctx)) | ||
| val (varargCount, varargBuild) = children.tail.zip(evals.tail).map { case (child, eval) => | ||
|
|
@@ -163,13 +190,18 @@ case class ConcatWs(children: Seq[Expression]) | |
| } | ||
| }.unzip | ||
|
|
||
| ev.copy(evals.map(_.code).mkString("\n") + | ||
| // ev.copy(evals.map(_.code).mkString("\n") + | ||
|
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. Forget to remove commented code?
Member
Author
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. thanks :) |
||
| val codes = ctx.splitExpressions(ctx.INPUT_ROW, evals.map(_.code)) | ||
| val varargCounts = ctx.splitExpressions(ctx.INPUT_ROW, varargCount) | ||
| val varargBuilds = ctx.splitExpressions(ctx.INPUT_ROW, varargBuild) | ||
| ev.copy( | ||
| s""" | ||
| int $varargNum = ${children.count(_.dataType == StringType) - 1}; | ||
| int $idxInVararg = 0; | ||
| ${varargCount.mkString("\n")} | ||
| UTF8String[] $array = new UTF8String[$varargNum]; | ||
| ${varargBuild.mkString("\n")} | ||
| $codes | ||
| $varargNum = ${children.count(_.dataType == StringType) - 1}; | ||
| $idxInVararg = 0; | ||
| $varargCounts | ||
| $array = new UTF8String[$varargNum]; | ||
| $varargBuilds | ||
| UTF8String ${ev.value} = UTF8String.concatWs(${evals.head.value}, $array); | ||
| 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.
nit:
numArgs.