maropu commented on a change in pull request #25806: [SPARK-29100][SQL] Fix
compilation error in codegen with switch from InSet expression
URL: https://github.com/apache/spark/pull/25806#discussion_r324953649
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
##########
@@ -457,17 +457,25 @@ case class InSet(child: Expression, hset: Set[Any])
extends UnaryExpression with
break;
""")
+ val switchCode = if (caseBranches.size > 0) {
Review comment:
We don't need to compute `caseBranches`, too, if hset is empty?
```
val valueGen = child.genCode(ctx)
val switchCode = if (hset.isEmpty) {
val caseValuesGen = hset.filter(_ != null).map(Literal(_).genCode(ctx))
val caseBranches = caseValuesGen.map(literal =>
code"""
case ${literal.value}:
${ev.value} = true;
break;
""")
code"""
switch (${valueGen.value}) {
${caseBranches.mkString("\n")}
default:
${ev.isNull} = $hasNull;
}
"""
} else {
s"${ev.isNull} = $hasNull;"
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]