Skip to content

Commit f9aba06

Browse files
committed
unit tests
1 parent c78166d commit f9aba06

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,13 @@ object CombineUnions extends Rule[LogicalPlan] {
825825
object 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

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)