Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13243#discussion_r64166173
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
 ---
    @@ -232,27 +232,54 @@ case class NewInstance(
     
       override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
         val javaType = ctx.javaType(dataType)
    -    val argGen = arguments.map(_.genCode(ctx))
    -    val argString = argGen.map(_.value).mkString(", ")
    +    val argIsNulls = ctx.freshName("argIsNulls")
    +    ctx.addMutableState("boolean[]", argIsNulls,
    +      s"$argIsNulls = new boolean[${arguments.size}];")
    +    val argValues = arguments.zipWithIndex.map { case (e, i) =>
    +      val argValue = ctx.freshName("argValue")
    +      ctx.addMutableState(ctx.javaType(e.dataType), argValue, "")
    +      argValue
    +    }
    +
    +    val argCodes = arguments.zipWithIndex.map { case (e, i) =>
    +      val expr = e.genCode(ctx)
    +      expr.code + s"""
    +       $argIsNulls[$i] = ${expr.isNull};
    +       ${argValues(i)} = ${expr.value};
    +     """
    +    }
    +    val argCode = ctx.splitExpressions(ctx.INPUT_ROW, argCodes)
     
         val outer = outerPointer.map(func => 
Literal.fromObject(func()).genCode(ctx))
     
         var isNull = ev.isNull
         val setIsNull = if (propagateNull && arguments.nonEmpty) {
    -      s"final boolean $isNull = ${argGen.map(_.isNull).mkString(" || ")};"
    +      if (arguments.length <= 10) {
    +        val argIsNull = arguments.zipWithIndex.map { case (e, i) =>
    +          s"$argIsNulls[$i]"
    +        }
    +        s"final boolean $isNull = ${argIsNull.mkString(" || ")};"
    +      } else {
    +        s"""
    +         boolean $isNull = false;
    +         for (int idx = 0; idx < ${arguments.length}; idx++) {
    +           if ($argIsNulls[idx]) { $isNull = true; break; }
    +         }
    +       """
    +      }
         } else {
           isNull = "false"
           ""
         }
     
         val constructorCall = outer.map { gen =>
    -      s"""${gen.value}.new ${cls.getSimpleName}($argString)"""
    +      s"""${gen.value}.new ${cls.getSimpleName}(${argValues.mkString(", 
")})"""
         }.getOrElse {
    -      s"new $className($argString)"
    +      s"new $className(${argValues.mkString(", ")})"
         }
     
         val code = s"""
    -      ${argGen.map(_.code).mkString("\n")}
    +      ${argCode.mkString("")}
    --- End diff --
    
    Isn't `argCode` already a string?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to