Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/19901#discussion_r155134265
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala
---
@@ -240,31 +239,35 @@ case class CaseWhen(
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)
+ returnType = ctx.JAVA_BYTE,
+ makeSplitFunction = {
+ func =>
+ s"""
+ ${ctx.JAVA_BYTE} $conditionMet = -1;
+ do {
+ $func
+ } while (false);
+ return $conditionMet;
+ """
+ },
+ foldFunctions = { funcCalls =>
+ funcCalls.map { funcCall =>
+ s"""
+ $conditionMet = $funcCall;
+ if ($conditionMet != -1) {
+ continue;
+ }"""
+ }.mkString
+ })
ev.copy(code = s"""
- ${ev.isNull} = true;
- ${ev.value} = ${ctx.defaultValue(dataType)};
- ${ctx.JAVA_BOOLEAN} $conditionMet = false;
+ ${ctx.JAVA_BYTE} $conditionMet = -1;
+ $value = ${ctx.defaultValue(dataType)};
do {
$codes
- } while (false);""")
+ } while (false);
+ boolean ${ev.isNull} = ($conditionMet != 0); // TRUE if -1 or 1
--- End diff --
Maybe `// TRUE if any condition is met and the result is not null, or no
any condition is met.`
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]