Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22029#discussion_r229700708
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
 ---
    @@ -212,27 +212,34 @@ object ReorderAssociativeOperator extends 
Rule[LogicalPlan] {
      * 1. Converts the predicate to false when the list is empty and
      *    the value is not nullable.
      * 2. Removes literal repetitions.
    - * 3. Replaces [[In (value, seq[Literal])]] with optimized version
    - *    [[InSet (value, HashSet[Literal])]] which is much faster.
    + * 3. Replaces [[In (values, seq[Literal])]] with optimized version
    + *    [[InSet (values, HashSet[Literal])]] which is much faster.
      */
     object OptimizeIn extends Rule[LogicalPlan] {
       def apply(plan: LogicalPlan): LogicalPlan = plan transform {
         case q: LogicalPlan => q transformExpressionsDown {
    -      case In(v, list) if list.isEmpty =>
    -        // When v is not nullable, the following expression will be 
optimized
    +      case i @ In(values, list) if list.isEmpty =>
    +        // When values are not nullable, the following expression will be 
optimized
             // to FalseLiteral which is tested in OptimizeInSuite.scala
    -        If(IsNotNull(v), FalseLiteral, Literal(null, BooleanType))
    -      case expr @ In(v, list) if expr.inSetConvertible =>
    +        val isNotNull = if (SQLConf.get.inFalseForNullField) {
    +          IsNotNull(i.value)
    +        } else {
    +          val valuesNotNull: Seq[Expression] = values.map(IsNotNull)
    +          valuesNotNull.tail.foldLeft(valuesNotNull.head)(And)
    --- End diff --
    
    nit: `values.map(IsNotNull).reduce(And)`


---

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

Reply via email to