-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-22543][SQL] fix java 64kb compile error for deeply nested expressions #19767
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 all commits
e63bb6e
d126977
c875329
86cba3c
29188fe
6bea161
e494844
c015d33
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 |
---|---|---|
|
@@ -64,52 +64,22 @@ case class If(predicate: Expression, trueValue: Expression, falseValue: Expressi | |
val trueEval = trueValue.genCode(ctx) | ||
val falseEval = falseValue.genCode(ctx) | ||
|
||
// place generated code of condition, true value and false value in separate methods if | ||
// their code combined is large | ||
val combinedLength = condEval.code.length + trueEval.code.length + falseEval.code.length | ||
|
||
val generatedCode = if (combinedLength > 1024 && | ||
// Split these expressions only if they are created from a row object | ||
(ctx.INPUT_ROW != null && ctx.currentVars == null)) { | ||
|
||
val (condFuncName, condGlobalIsNull, condGlobalValue) = | ||
ctx.createAndAddFunction(condEval, predicate.dataType, "evalIfCondExpr") | ||
val (trueFuncName, trueGlobalIsNull, trueGlobalValue) = | ||
ctx.createAndAddFunction(trueEval, trueValue.dataType, "evalIfTrueExpr") | ||
val (falseFuncName, falseGlobalIsNull, falseGlobalValue) = | ||
ctx.createAndAddFunction(falseEval, falseValue.dataType, "evalIfFalseExpr") | ||
val code = | ||
s""" | ||
$condFuncName(${ctx.INPUT_ROW}); | ||
boolean ${ev.isNull} = false; | ||
${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)}; | ||
if (!$condGlobalIsNull && $condGlobalValue) { | ||
$trueFuncName(${ctx.INPUT_ROW}); | ||
${ev.isNull} = $trueGlobalIsNull; | ||
${ev.value} = $trueGlobalValue; | ||
} else { | ||
$falseFuncName(${ctx.INPUT_ROW}); | ||
${ev.isNull} = $falseGlobalIsNull; | ||
${ev.value} = $falseGlobalValue; | ||
} | ||
""" | ||
} | ||
else { | ||
s""" | ||
${condEval.code} | ||
boolean ${ev.isNull} = false; | ||
${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)}; | ||
if (!${condEval.isNull} && ${condEval.value}) { | ||
${trueEval.code} | ||
${ev.isNull} = ${trueEval.isNull}; | ||
${ev.value} = ${trueEval.value}; | ||
} else { | ||
${falseEval.code} | ||
${ev.isNull} = ${falseEval.isNull}; | ||
${ev.value} = ${falseEval.value}; | ||
} | ||
""" | ||
} | ||
|
||
ev.copy(code = generatedCode) | ||
|${condEval.code} | ||
|boolean ${ev.isNull} = false; | ||
|${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)}; | ||
|if (!${condEval.isNull} && ${condEval.value}) { | ||
| ${trueEval.code} | ||
| ${ev.isNull} = ${trueEval.isNull}; | ||
| ${ev.value} = ${trueEval.value}; | ||
|} else { | ||
| ${falseEval.code} | ||
| ${ev.isNull} = ${falseEval.isNull}; | ||
| ${ev.value} = ${falseEval.value}; | ||
|} | ||
""".stripMargin | ||
ev.copy(code = code) | ||
} | ||
|
||
override def toString: String = s"if ($predicate) $trueValue else $falseValue" | ||
|
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.
why is this needed? I think we can use
eval.value
instead of itThere 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.
ev.value
may be a global variable and here we need a 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.
why do we strictly need a local variable here? Can't we simply assign
ev.value
to the generated function return value?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.
then how are we going to change this?
eval.code = s"$javaType $newValue = $funcFullName(${ctx.INPUT_ROW});"
Saving a local variable is nothing and I think we shouldn't complicate the code(check if a variable is global) because of this.
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.
ah, do you mean just do
eval.value = s"$funcFullName(${ctx.INPUT_ROW})"
? Let me tryUh oh!
There was an error while loading. Please reload this page.
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 meant:
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.
this won't work because
${eval.value}
is not declared if it's not a global variable. I went withThere 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 see, sorry, you're right. Then I think your previous solution is better: in this way if
eval.value
is used multiple times we are recomputing the function every time, thus your original implementation was fine, sorry for the bad comment.