Skip to content

Commit b8853a0

Browse files
wangyumgengliangwang
authored andcommitted
Add test rewrite complex join predicates to conjunctive normal form
1 parent 01c330c commit b8853a0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,26 @@ class FilterPushdownSuite extends PlanTest {
12791279
comparePlans(optimized, correctAnswer)
12801280
}
12811281

1282+
test("inner join: rewrite complex join predicates to conjunctive normal form") {
1283+
val x = testRelation.subquery('x)
1284+
val y = testRelation.subquery('y)
1285+
1286+
val joinCondition = (("x.b".attr === "y.b".attr)
1287+
&& ((("x.a".attr === 5) && ("y.a".attr >= 2) && ("y.a".attr <= 3))
1288+
|| (("x.a".attr === 2) && ("y.a".attr >= 1) && ("y.a".attr <= 14))
1289+
|| (("x.a".attr === 1) && ("y.a".attr >= 9) && ("y.a".attr <= 27))))
1290+
1291+
val originalQuery = x.join(y, condition = Some(joinCondition))
1292+
val optimized = Optimize.execute(originalQuery.analyze)
1293+
val left = testRelation.where(
1294+
('a === 5 || 'a === 2 || 'a === 1)).subquery('x)
1295+
val right = testRelation.where(
1296+
('a >= 2 && 'a <= 3) || ('a >= 1 && 'a <= 14) || ('a >= 9 && 'a <= 27)).subquery('y)
1297+
val correctAnswer = left.join(right, condition = Some(joinCondition)).analyze
1298+
1299+
comparePlans(optimized, correctAnswer)
1300+
}
1301+
12821302
test("inner join: rewrite join predicates(with NOT predicate) to conjunctive normal form") {
12831303
val x = testRelation.subquery('x)
12841304
val y = testRelation.subquery('y)

0 commit comments

Comments
 (0)