Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/15901#discussion_r88598628
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
---
@@ -245,51 +311,35 @@ case class NewInstance(
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val javaType = ctx.javaType(dataType)
- 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 (argCode, argString, resultIsNull) = prepareArguments(ctx, ev)
val outer = outerPointer.map(func =>
Literal.fromObject(func()).genCode(ctx))
var isNull = ev.isNull
- val setIsNull = if (propagateNull && arguments.nonEmpty) {
- s"""
- boolean $isNull = false;
- for (int idx = 0; idx < ${arguments.length}; idx++) {
- if ($argIsNulls[idx]) { $isNull = true; break; }
- }
- """
+ val prepareIsNull = if (needNullCheck) {
+ s"boolean $isNull = $resultIsNull;"
} else {
isNull = "false"
""
}
val constructorCall = outer.map { gen =>
- s"""${gen.value}.new ${cls.getSimpleName}(${argValues.mkString(",
")})"""
+ s"${gen.value}.new ${cls.getSimpleName}($argString)"
}.getOrElse {
- s"new $className(${argValues.mkString(", ")})"
+ s"new $className($argString)"
}
val code = s"""
$argCode
${outer.map(_.code).getOrElse("")}
- $setIsNull
- final $javaType ${ev.value} = $isNull ?
${ctx.defaultValue(javaType)} : $constructorCall;
- """
+ $prepareIsNull
+ """ +
+ (if (needNullCheck) {
+ s"final $javaType ${ev.value} = $isNull ?
${ctx.defaultValue(javaType)} : $constructorCall;"
--- End diff --
sorry I mean "java compiler"... I think janino is smart enough about it.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]