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

    https://github.com/apache/spark/pull/19901#discussion_r155403618
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala
 ---
    @@ -212,59 +216,63 @@ case class CaseWhen(
           val res = elseExpr.genCode(ctx)
           s"""
              |${res.code}
    -         |${ev.isNull} = ${res.isNull};
    -         |${ev.value} = ${res.value};
    +         |$resultState = (byte)(${res.isNull} ? $HAS_NULL : $HAS_NONNULL);
    +         |$tmpResult = ${res.value};
            """.stripMargin
         }
     
         val allConditions = cases ++ elseCode
     
         // This generates code like:
    -    //   conditionMet = caseWhen_1(i);
    -    //   if(conditionMet) {
    +    //   caseWhenResultState = caseWhen_1(i);
    +    //   if(caseWhenResultState != -1) {
         //     continue;
         //   }
    -    //   conditionMet = caseWhen_2(i);
    -    //   if(conditionMet) {
    +    //   caseWhenResultState = caseWhen_2(i);
    +    //   if(caseWhenResultState != -1) {
         //     continue;
         //   }
         //   ...
         // and the declared methods are:
    -    //   private boolean caseWhen_1234() {
    -    //     boolean conditionMet = false;
    +    //   private byte caseWhen_1234() {
    +    //     byte caseWhenResultState = -1;
         //     do {
         //       // here the evaluation of the conditions
         //     } while (false);
    -    //     return conditionMet;
    +    //     return caseWhenResultState;
         //   }
         val codes = ctx.splitExpressionsWithCurrentInputs(
           expressions = allConditions,
           funcName = "caseWhen",
    -      returnType = ctx.JAVA_BOOLEAN,
    +      returnType = ctx.JAVA_BYTE,
           makeSplitFunction = func =>
             s"""
    -           |${ctx.JAVA_BOOLEAN} $conditionMet = false;
    +           |${ctx.JAVA_BYTE} $resultState = $NOT_MATCHED;
                |do {
                |  $func
                |} while (false);
    -           |return $conditionMet;
    +           |return $resultState;
              """.stripMargin,
           foldFunctions = _.map { funcCall =>
             s"""
    -           |$conditionMet = $funcCall;
    -           |if ($conditionMet) {
    +           |$resultState = $funcCall;
    +           |if ($resultState != $NOT_MATCHED) {
                |  continue;
                |}
              """.stripMargin
           }.mkString)
     
    -    ev.copy(code = s"""
    -      ${ev.isNull} = true;
    -      ${ev.value} = ${ctx.defaultValue(dataType)};
    -      ${ctx.JAVA_BOOLEAN} $conditionMet = false;
    -      do {
    -        $codes
    -      } while (false);""")
    +    ev.copy(code =
    +      s"""
    +         |${ctx.JAVA_BYTE} $resultState = $NOT_MATCHED;
    +         |$tmpResult = ${ctx.defaultValue(dataType)};
    +         |do {
    +         |  $codes
    +         |} while (false);
    +         |// TRUE if any condition is met and the result is not null, or 
no any condition is met.
    --- End diff --
    
    Seems wrong here. `TRUE if any condition is met and the result is null...`


---

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

Reply via email to