Github user dbtsai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/23171#discussion_r237226275
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ---
    @@ -335,6 +343,41 @@ case class In(value: Expression, list: 
Seq[Expression]) extends Predicate {
            """.stripMargin)
       }
     
    +  private def genCodeWithSwitch(ctx: CodegenContext, ev: ExprCode): 
ExprCode = {
    +    val (nullLiterals, nonNullLiterals) = list.partition {
    +      case Literal(null, _) => true
    +      case _ => false
    +    }
    +    val listGen = nonNullLiterals.map(_.genCode(ctx))
    +    val valueGen = value.genCode(ctx)
    +
    +    val caseBranches = listGen.map(literal =>
    +      s"""
    +         |case ${literal.value}:
    +         |  ${ev.value} = true;
    +         |  break;
    +       """.stripMargin)
    +
    +    ev.copy(code =
    +      code"""
    +         |${valueGen.code}
    +         |${CodeGenerator.JAVA_BOOLEAN} ${ev.isNull} = ${valueGen.isNull};
    +         |${CodeGenerator.JAVA_BOOLEAN} ${ev.value} = false;
    +         |if (!${valueGen.isNull}) {
    +         |  switch (${valueGen.value}) {
    +         |    ${caseBranches.mkString("")}
    +         |    default:
    +         |      ${ev.isNull} = ${nullLiterals.nonEmpty};
    +         |  }
    +         |}
    +       """.stripMargin)
    +  }
    +
    +  private def isSwitchCompatible: Boolean = list.forall {
    +    case Literal(_, dt) => dt == ByteType || dt == ShortType || dt == 
IntegerType
    --- End diff --
    
    ```scala
    case Literal(_, dt) if dt == ByteType || dt == ShortType || dt == 
IntegerType => true
    ```
    is easier to read?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to