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

    https://github.com/apache/spark/pull/19895#discussion_r155030637
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala
 ---
    @@ -219,57 +219,51 @@ case class CaseWhen(
     
         val allConditions = cases ++ elseCode
     
    -    val code = if (ctx.INPUT_ROW == null || ctx.currentVars != null) {
    -        allConditions.mkString("\n")
    -      } else {
    -        // This generates code like:
    -        //   conditionMet = caseWhen_1(i);
    -        //   if(conditionMet) {
    -        //     continue;
    -        //   }
    -        //   conditionMet = caseWhen_2(i);
    -        //   if(conditionMet) {
    -        //     continue;
    -        //   }
    -        //   ...
    -        // and the declared methods are:
    -        //   private boolean caseWhen_1234() {
    -        //     boolean conditionMet = false;
    -        //     do {
    -        //       // here the evaluation of the conditions
    -        //     } while (false);
    -        //     return conditionMet;
    -        //   }
    -        ctx.splitExpressions(allConditions, "caseWhen",
    -          ("InternalRow", ctx.INPUT_ROW) :: Nil,
    -          returnType = ctx.JAVA_BOOLEAN,
    -          makeSplitFunction = {
    -            func =>
    -              s"""
    -                ${ctx.JAVA_BOOLEAN} $conditionMet = false;
    -                do {
    -                  $func
    -                } while (false);
    -                return $conditionMet;
    -              """
    -          },
    -          foldFunctions = { funcCalls =>
    -            funcCalls.map { funcCall =>
    -              s"""
    -                $conditionMet = $funcCall;
    -                if ($conditionMet) {
    -                  continue;
    -                }"""
    -            }.mkString
    -          })
    -      }
    +    // This generates code like:
    +    //   conditionMet = caseWhen_1(i);
    +    //   if(conditionMet) {
    +    //     continue;
    +    //   }
    +    //   conditionMet = caseWhen_2(i);
    +    //   if(conditionMet) {
    +    //     continue;
    +    //   }
    +    //   ...
    +    // and the declared methods are:
    +    //   private boolean caseWhen_1234() {
    +    //     boolean conditionMet = false;
    +    //     do {
    +    //       // here the evaluation of the conditions
    +    //     } while (false);
    +    //     return conditionMet;
    +    //   }
    +    val codes = ctx.splitExpressionsWithCurrentInputs(
    +      expressions = allConditions,
    +      funcName = "caseWhen",
    +      returnType = ctx.JAVA_BOOLEAN,
    +      makeSplitFunction = func =>
    +        s"""
    +           |${ctx.JAVA_BOOLEAN} $conditionMet = false;
    +           |do {
    +           |  $func
    +           |} while (false);
    +           |return $conditionMet;
    +         """.stripMargin,
    +      foldFunctions = _.map { funcCall =>
    +        s"""
    +           |$conditionMet = $funcCall;
    +           |if ($conditionMet) {
    +           |  continue;
    +           |}
    +         """.stripMargin
    +      }.mkString)
     
         ev.copy(code = s"""
           ${ev.isNull} = true;
           ${ev.value} = ${ctx.defaultValue(dataType)};
           ${ctx.JAVA_BOOLEAN} $conditionMet = false;
           do {
    -        $code
    +        $codes
    --- End diff --
    
    Nit: `code`
    
    > In computer science, "code" is used as a mass noun, specifying the 
collection of instructions in a specific arrangement as a whole and in no 
specific quantity. Whether it's one line of code or ten pages, it is still 
referred to as code, not codes.



---

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

Reply via email to