Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/19901#discussion_r155404828
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
---
@@ -237,37 +237,44 @@ 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 has 3 possible values:
+ // -1 means no matches found and there is at least one value in the
list evaluated
+ val HAS_NULL = -1
+ // 0 means no matches found and all values in the list are not null
+ val NOT_MATCHED = 0
+ // 1 means one value in the list is matched
+ val MATCHED = 1
+ val tmpResult = 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;
+ | $tmpResult = $HAS_NULL; // ${ev.isNull} = true;
|} else if (${ctx.genEqual(value.dataType, valueArg, x.value)}) {
- | ${ev.isNull} = false;
- | ${ev.value} = true;
+ | $tmpResult = $MATCHED; // ${ev.isNull} = false; ${ev.value} =
true;
--- End diff --
ditto.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]