Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/19895#discussion_r155125939
--- 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 --
ah good to know it. I'll change them in related PRs later.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]