Github user mgaido91 commented on a diff in the pull request:
https://github.com/apache/spark/pull/19767#discussion_r152569647
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
---
@@ -104,16 +104,48 @@ abstract class Expression extends
TreeNode[Expression] {
}.getOrElse {
val isNull = ctx.freshName("isNull")
val value = ctx.freshName("value")
- val ve = doGenCode(ctx, ExprCode("", isNull, value))
- if (ve.code.nonEmpty) {
+ val eval = doGenCode(ctx, ExprCode("", isNull, value))
+ reduceCodeSize(ctx, eval)
+ if (eval.code.nonEmpty) {
// Add `this` in the comment.
- ve.copy(code = s"${ctx.registerComment(this.toString)}\n" +
ve.code.trim)
+ eval.copy(code = s"${ctx.registerComment(this.toString)}\n" +
eval.code.trim)
} else {
- ve
+ eval
}
}
}
+ private def reduceCodeSize(ctx: CodegenContext, eval: ExprCode): Unit = {
+ // TODO: support whole stage codegen too
+ if (eval.code.trim.length > 500 && ctx.INPUT_ROW != null &&
ctx.currentVars == null) {
+ val setIsNull = if (eval.isNull != "false" && eval.isNull != "true")
{
+ val globalIsNull = ctx.freshName("globalIsNull")
+ ctx.addMutableState(ctx.JAVA_BOOLEAN, globalIsNull)
+ val localIsNull = eval.isNull
+ eval.isNull = globalIsNull
+ s"$globalIsNull = $localIsNull;"
+ } else {
+ ""
+ }
+
+ val javaType = ctx.javaType(dataType)
+ val newValue = ctx.freshName("value")
--- End diff --
I think it would simply become:
```
eval.code = s"${eval.value} = $funcFullName(${ctx.INPUT_ROW});"
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]