You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/02/22 05:06:16 UTC

[GitHub] [spark] gengliangwang commented on a change in pull request #31318: [SPARK-34222][SQL] Enhance boolean simplification rule

gengliangwang commented on a change in pull request #31318:
URL: https://github.com/apache/spark/pull/31318#discussion_r579986647



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -366,22 +367,34 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper {
             // ((c || ...) && (d || ...)) || a || b
             (common :+ And(ldiff.reduce(Or), rdiff.reduce(Or))).reduce(Or)
           }
+        } else {
+          // No common factors from disjunctive predicates, reduce common factor from conjunction
+          val all = splitConjunctivePredicates(left) ++ splitConjunctivePredicates(right)
+          val distinct = ExpressionSet(all)
+          if (all.size == distinct.size) {
+            // No common factors, return the original predicate
+            and
+          } else {
+            // (((a && b) && a && (a && c))) => a && b && c
+            distinct.reduce(And)

Review comment:
       @cloud-fan yes that would be helpful, especially in filter pushdown of data sources.




----------------------------------------------------------------
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:
users@infra.apache.org



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