Skip to content

Commit a051700

Browse files
committed
update test case
1 parent 005f6fe commit a051700

File tree

2 files changed

+43
-38
lines changed

2 files changed

+43
-38
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -208,43 +208,48 @@ trait PredicateHelper extends Logging {
208208
*/
209209
protected def convertibleFilter(
210210
condition: Expression,
211-
outputSet: AttributeSet): Option[Expression] = condition match {
212-
case And(left, right) =>
213-
val leftResultOptional = convertibleFilter(left, outputSet)
214-
val rightResultOptional = convertibleFilter(right, outputSet)
215-
(leftResultOptional, rightResultOptional) match {
216-
case (Some(leftResult), Some(rightResult)) => Some(And(leftResult, rightResult))
217-
case (Some(leftResult), None) => Some(leftResult)
218-
case (None, Some(rightResult)) => Some(rightResult)
219-
case _ => None
220-
}
211+
outputSet: AttributeSet): Option[Expression] = {
212+
println("condition: " + condition)
213+
val ret = condition match {
214+
case And(left, right) =>
215+
val leftResultOptional = convertibleFilter(left, outputSet)
216+
val rightResultOptional = convertibleFilter(right, outputSet)
217+
(leftResultOptional, rightResultOptional) match {
218+
case (Some(leftResult), Some(rightResult)) => Some(And(leftResult, rightResult))
219+
case (Some(leftResult), None) => Some(leftResult)
220+
case (None, Some(rightResult)) => Some(rightResult)
221+
case _ => None
222+
}
221223

222-
// The Or predicate is convertible when both of its children can be pushed down.
223-
// That is to say, if one/both of the children can be partially pushed down, the Or
224-
// predicate can be partially pushed down as well.
225-
//
226-
// Here is an example used to explain the reason.
227-
// Let's say we have
228-
// (a1 AND a2) OR (b1 AND b2),
229-
// a1 and b1 is convertible, while a2 and b2 is not.
230-
// The predicate can be converted as
231-
// (a1 OR b1) AND (a1 OR b2) AND (a2 OR b1) AND (a2 OR b2)
232-
// As per the logical in And predicate, we can push down (a1 OR b1).
233-
case Or(left, right) =>
234-
for {
235-
lhs <- convertibleFilter(left, outputSet)
236-
rhs <- convertibleFilter(right, outputSet)
237-
} yield Or(lhs, rhs)
238-
239-
// Here we assume all the `Not` operators is already below all the `And` and `Or` operators
240-
// after the optimization rule `BooleanSimplification`, so that we don't need to handle the
241-
// `Not` operators here.
242-
case other =>
243-
if (other.references.subsetOf(outputSet)) {
244-
Some(other)
245-
} else {
246-
None
247-
}
224+
// The Or predicate is convertible when both of its children can be pushed down.
225+
// That is to say, if one/both of the children can be partially pushed down, the Or
226+
// predicate can be partially pushed down as well.
227+
//
228+
// Here is an example used to explain the reason.
229+
// Let's say we have
230+
// (a1 AND a2) OR (b1 AND b2),
231+
// a1 and b1 is convertible, while a2 and b2 is not.
232+
// The predicate can be converted as
233+
// (a1 OR b1) AND (a1 OR b2) AND (a2 OR b1) AND (a2 OR b2)
234+
// As per the logical in And predicate, we can push down (a1 OR b1).
235+
case Or(left, right) =>
236+
for {
237+
lhs <- convertibleFilter(left, outputSet)
238+
rhs <- convertibleFilter(right, outputSet)
239+
} yield Or(lhs, rhs)
240+
241+
// Here we assume all the `Not` operators is already below all the `And` and `Or` operators
242+
// after the optimization rule `BooleanSimplification`, so that we don't need to handle the
243+
// `Not` operators here.
244+
case other =>
245+
if (other.references.subsetOf(outputSet)) {
246+
Some(other)
247+
} else {
248+
None
249+
}
250+
}
251+
println("ret: " + ret)
252+
ret
248253
}
249254
}
250255

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ConvertibleFilterSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ConvertibleFilterSuite extends SparkFunSuite with PredicateHelper with Pla
7373
checkCondition((a || b) || (c && d) || (e && f) || (g && h), Seq(a, c, e, g), None)
7474
checkCondition((a || b) || (c && d) || (e && f) || (g && h), Seq(a, b, c, e, g),
7575
Some(a || b || c || e || g))
76-
checkCondition((a || b || c) && (d || e || f) || (g || h || i), Seq(b, e, h), Some(b || e || h))
77-
checkCondition((a || b || c) && (d || e || f) || (g || h || i), Seq(b, e, d), None)
76+
checkCondition((a && b && c) || (d && e && f) || (g && h && i), Seq(b, e, h), Some(b || e || h))
77+
checkCondition((a && b && c) || (d && e && f) || (g && h && i), Seq(b, e, d), None)
7878
}
7979
}

0 commit comments

Comments
 (0)