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

    https://github.com/apache/spark/pull/19767#discussion_r152539689
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
 ---
    @@ -105,6 +105,36 @@ abstract class Expression extends TreeNode[Expression] 
{
           val isNull = ctx.freshName("isNull")
           val value = ctx.freshName("value")
           val ve = doGenCode(ctx, ExprCode("", isNull, value))
    +
    +      // TODO: support whole stage codegen too
    +      if (ve.code.trim.length > 1024 && ctx.INPUT_ROW != null && 
ctx.currentVars == null) {
    +        val setIsNull = if (ve.isNull != "false" && ve.isNull != "true") {
    +          val globalIsNull = ctx.freshName("globalIsNull")
    +          ctx.addMutableState("boolean", globalIsNull, s"$globalIsNull = 
false;")
    +          val localIsNull = ve.isNull
    +          ve.isNull = globalIsNull
    +          s"$globalIsNull = $localIsNull;"
    +        } else {
    +          ""
    +        }
    +
    +        val javaType = ctx.javaType(dataType)
    +        val newValue = ctx.freshName("value")
    +
    +        val funcName = ctx.freshName(nodeName)
    +        val funcFullName = ctx.addNewFunction(funcName,
    +          s"""
    +             |private $javaType $funcName(InternalRow ${ctx.INPUT_ROW}) {
    --- End diff --
    
    thanks for this fix. I like your approach here.
    
    Actually what happens depends on the type of the variable and anyway I 
think that most of the time we are reinitializing anyway these objects, thus 
the only thing we are saving using global variables is the pointer and I am not 
sure if this is a big deal.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to