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

    https://github.com/apache/spark/pull/7452#discussion_r34830287
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -391,26 +391,26 @@ object BooleanSimplification extends 
Rule[LogicalPlan] with PredicateHelper {
             // (a || b) && (a || c)  =>  a || (b && c)
             case _ =>
               // 1. Split left and right to get the disjunctive predicates,
    -          //   i.e. lhsSet = (a, b), rhsSet = (a, c)
    +          //   i.e. lhs = (a, b), rhs = (a, c)
               // 2. Find the common predict between lhsSet and rhsSet, i.e. 
common = (a)
               // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = 
(b), rdiff = (c)
               // 4. Apply the formula, get the optimized predicate: common || 
(ldiff && rdiff)
    -          val lhsSet = splitDisjunctivePredicates(left).toSet
    -          val rhsSet = splitDisjunctivePredicates(right).toSet
    -          val common = lhsSet.intersect(rhsSet)
    +          val lhs = splitDisjunctivePredicates(left)
    +          val rhs = splitDisjunctivePredicates(right)
    +          val common = lhs.filter(e => rhs.exists(e.semanticEquals(_)))
               if (common.isEmpty) {
                 // No common factors, return the original predicate
                 and
               } else {
    -            val ldiff = lhsSet.diff(common)
    -            val rdiff = rhsSet.diff(common)
    +            val ldiff = lhs.filterNot(e => 
common.exists(e.semanticEquals(_)))
    +            val rdiff = rhs.filterNot(e => 
common.exists(e.semanticEquals(_)))
    --- End diff --
    
    Actually it's kind of ugly to use `semanticEquals` here. Another approach 
is normalizing the name of `AttributeReference`s inside `Filter`, as we don't 
need to do case-preserving for `Filter`, right?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to