File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
main/scala/org/apache/spark/sql/catalyst/optimizer
test/scala/org/apache/spark/sql/catalyst/optimizer Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -825,9 +825,13 @@ object CombineUnions extends Rule[LogicalPlan] {
825825object CombineFilters extends Rule [LogicalPlan ] with PredicateHelper {
826826 def apply (plan : LogicalPlan ): LogicalPlan = plan transform {
827827 case ff @ Filter (fc, nf @ Filter (nc, grandChild)) =>
828- val ac = (ExpressionSet (splitConjunctivePredicates(nc)) --
829- ExpressionSet (splitConjunctivePredicates(fc))).reduce(And )
830- Filter (And (ac, fc), grandChild)
828+ (ExpressionSet (splitConjunctivePredicates(fc)) --
829+ ExpressionSet (splitConjunctivePredicates(nc))).reduceOption(And ) match {
830+ case Some (ac) =>
831+ Filter (And (ac, nc), grandChild)
832+ case None =>
833+ nf
834+ }
831835 }
832836}
833837
Original file line number Diff line number Diff line change @@ -81,6 +81,21 @@ class FilterPushdownSuite extends PlanTest {
8181 comparePlans(optimized, correctAnswer)
8282 }
8383
84+ test(" combine redundant filters" ) {
85+ val originalQuery =
86+ testRelation
87+ .where(' a === 1 && ' b === 1 )
88+ .where(' a === 1 && ' c === 1 )
89+
90+ val optimized = Optimize .execute(originalQuery.analyze)
91+ val correctAnswer =
92+ testRelation
93+ .where(' a === 1 && ' b === 1 && ' c === 1 )
94+ .analyze
95+
96+ comparePlans(optimized, correctAnswer)
97+ }
98+
8499 test(" can't push without rewrite" ) {
85100 val originalQuery =
86101 testRelation
You can’t perform that action at this time.
0 commit comments