You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by hvanhovell <gi...@git.apache.org> on 2016/11/04 18:03:05 UTC

[GitHub] spark pull request #15693: [SPARK-18125][SQL] Fix a compilation error in cod...

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

    https://github.com/apache/spark/pull/15693#discussion_r86601596
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ReferenceToExpressions.scala ---
    @@ -63,15 +63,33 @@ case class ReferenceToExpressions(result: Expression, children: Seq[Expression])
     
       override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
         val childrenGen = children.map(_.genCode(ctx))
    -    val childrenVars = childrenGen.zip(children).map {
    -      case (childGen, child) => LambdaVariable(childGen.value, childGen.isNull, child.dataType)
    -    }
    +    val (childrenVars, classChildrenVars) = childrenGen.zip(children).map {
    +      case (childGen, child) =>
    +        val childVar = LambdaVariable(childGen.value, childGen.isNull, child.dataType)
    +
    +        // SPARK-18125: The children vars are local variables. If the result expression uses
    +        // splitExpression, those variables cannot be accessed so compilation fails.
    +        // To fix it, we use class variables to hold those local variables.
    +        val classChildVarName = ctx.freshName("classChildVar")
    +        val classChildVarIsNull = ctx.freshName("classChildVarIsNull")
    +        ctx.addMutableState(ctx.javaType(childVar.dataType), classChildVarName, "")
    +        ctx.addMutableState("boolean", classChildVarIsNull, "")
    +        val classChildVar =
    +          LambdaVariable(classChildVarName, classChildVarIsNull, childVar.dataType)
    +
    +        (childVar, classChildVar)
    +    }.unzip
    +
    +    val initClassChildrenVars = classChildrenVars.zipWithIndex.map { case (classChildrenVar, i) =>
    --- End diff --
    
    Why not generate this code in the previous block?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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