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

    https://github.com/apache/spark/pull/19901#discussion_r155169598
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullExpressions.scala
 ---
    @@ -91,29 +91,36 @@ case class Coalesce(children: Seq[Expression]) extends 
Expression {
         val codes = ctx.splitExpressionsWithCurrentInputs(
           expressions = evals,
           funcName = "coalesce",
    -      makeSplitFunction = func =>
    -        s"""
    -           |do {
    -           |  $func
    -           |} while (false);
    -         """.stripMargin,
    -      foldFunctions = _.map { funcCall =>
    -        s"""
    -           |$funcCall;
    -           |if (!${ev.isNull}) {
    -           |  continue;
    -           |}
    -         """.stripMargin
    -      }.mkString)
    -
    +      returnType = ctx.javaType(dataType),
    +      makeSplitFunction = {
    +        func =>
    +          s"""
    +            |${ctx.javaType(dataType)} ${ev.value} = 
${ctx.defaultValue(dataType)};
    +            |do {
    +            |  $func
    +            |} while (false);
    +            |return ${ev.value};
    +          """.stripMargin
    +      },
    +      foldFunctions = { funcCalls =>
    +        funcCalls.map { funcCall =>
    +          s"""
    +             |${ev.value} = $funcCall;
    +             |if (!$coalesceTmpIsNull) {
    +             |  continue;
    +             |}
    +           """.stripMargin
    +        }.mkString
    +      })
     
         ev.copy(code =
           s"""
    -         |${ev.isNull} = true;
    -         |${ev.value} = ${ctx.defaultValue(dataType)};
    +         |$coalesceTmpIsNull = true;
    +         |${ctx.javaType(dataType)} ${ev.value} = 
${ctx.defaultValue(dataType)};
              |do {
              |  $codes
              |} while (false);
    +         |boolean ${ev.isNull} = $coalesceTmpIsNull;
    --- End diff --
    
    nit: `final`


---

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

Reply via email to