Github user mgaido91 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19767#discussion_r152567152
  
    --- 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 --
    
    why do we strictly need a local variable here? Can't we simply assign 
`ev.value` to the generated function return value?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to