Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/19901#discussion_r155168926
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
---
@@ -237,53 +237,60 @@ case class In(value: Expression, list:
Seq[Expression]) extends Predicate {
val javaDataType = ctx.javaType(value.dataType)
val valueGen = value.genCode(ctx)
val listGen = list.map(_.genCode(ctx))
- ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.value)
- ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull)
+ // inTmpResult -1 indicates at lease one expr in list is evaluated to
null.
+ // 0 means no matches found. 1 means the expr in list matches the
given value expr.
+ val inTmpResult = ctx.freshName("inTmpResult")
val valueArg = ctx.freshName("valueArg")
// All the blocks are meant to be inside a do { ... } while (false);
loop.
// The evaluation of variables can be stopped when we find a matching
value.
val listCode = listGen.map(x =>
s"""
|${x.code}
|if (${x.isNull}) {
- | ${ev.isNull} = true;
+ | $inTmpResult = -1; // isNull = true
|} else if (${ctx.genEqual(value.dataType, valueArg, x.value)}) {
- | ${ev.isNull} = false;
- | ${ev.value} = true;
+ | $inTmpResult = 1; // value = TRUE
| continue;
|}
""".stripMargin)
val codes = ctx.splitExpressionsWithCurrentInputs(
expressions = listCode,
funcName = "valueIn",
- extraArguments = (javaDataType, valueArg) :: Nil,
- makeSplitFunction = body =>
+ extraArguments = (javaDataType, valueArg) :: (ctx.JAVA_BYTE,
inTmpResult) :: Nil,
+ returnType = ctx.JAVA_BYTE,
+ makeSplitFunction = { body =>
s"""
|do {
| $body
|} while (false);
- """.stripMargin,
- foldFunctions = _.map { funcCall =>
- s"""
- |$funcCall;
- |if (${ev.value}) {
- | continue;
- |}
+ |return $inTmpResult;
""".stripMargin
- }.mkString("\n"))
+ },
+ foldFunctions = { funcCalls =>
+ funcCalls.map(funcCall =>
+ s"""
+ |$inTmpResult = $funcCall;
+ |if ($inTmpResult == 1) {
+ | continue;
+ |}
+ """.stripMargin).mkString("\n")
+ }
+ )
ev.copy(code =
s"""
|${valueGen.code}
- |${ev.value} = false;
- |${ev.isNull} = ${valueGen.isNull};
- |if (!${ev.isNull}) {
+ |// TRUE if any condition is met and the result is not null, or
no any condition is met.
--- End diff --
This comment I think is for `CaseWhen`?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]