@@ -1293,14 +1293,7 @@ class FilterPushdownSuite extends PlanTest {
1293
1293
val left = testRelation.where(
1294
1294
(' a === 5 || ' a === 2 || ' a === 1 )).subquery(' x )
1295
1295
val right = testRelation.where(
1296
- (' a >= 2 || ' a >= 1 || ' a >= 9 ) &&
1297
- (' a >= 2 || ' a >= 1 || ' a <= 27 ) &&
1298
- (' a >= 2 || ' a <= 14 || ' a >= 9 ) &&
1299
- (' a >= 2 || ' a <= 14 || ' a <= 27 ) &&
1300
- (' a <= 3 || ' a >= 1 || ' a >= 9 ) &&
1301
- (' a <= 3 || ' a >= 1 || ' a <= 27 ) &&
1302
- (' a <= 3 || ' a <= 14 || ' a >= 9 ) &&
1303
- (' a <= 3 || ' a <= 14 || ' a <= 27 )).subquery(' y )
1296
+ (' a >= 2 && ' a <= 3 ) || (' a >= 1 && ' a <= 14 ) || (' a >= 9 && ' a <= 27 )).subquery(' y )
1304
1297
val correctAnswer = left.join(right, condition = Some (joinCondition)).analyze
1305
1298
1306
1299
comparePlans(optimized, correctAnswer)
@@ -1367,6 +1360,25 @@ class FilterPushdownSuite extends PlanTest {
1367
1360
comparePlans(optimized, correctAnswer)
1368
1361
}
1369
1362
1363
+ test(" inner join: rewrite to conjunctive normal form avoid generating too many predicates" ) {
1364
+ val x = testRelation.subquery(' x )
1365
+ val y = testRelation.subquery(' y )
1366
+
1367
+ val originalQuery = {
1368
+ x.join(y, condition = Some ((" x.b" .attr === " y.b" .attr) && (((" x.a" .attr > 3 ) &&
1369
+ (" x.a" .attr < 13 ) && (" y.c" .attr <= 5 )) || ((" y.a" .attr > 2 ) && (" y.c" .attr < 1 )))))
1370
+ }
1371
+
1372
+ val optimized = Optimize .execute(originalQuery.analyze)
1373
+ val left = testRelation.subquery(' x )
1374
+ val right = testRelation.where(' c <= 5 || (' a > 2 && ' c < 1 )).subquery(' y )
1375
+ val correctAnswer = left.join(right, condition = Some (" x.b" .attr === " y.b" .attr &&
1376
+ (((" x.a" .attr > 3 ) && (" x.a" .attr < 13 ) && (" y.c" .attr <= 5 )) ||
1377
+ ((" y.a" .attr > 2 ) && (" y.c" .attr < 1 ))))).analyze
1378
+
1379
+ comparePlans(optimized, correctAnswer)
1380
+ }
1381
+
1370
1382
test(s " Disable rewrite to CNF by setting ${SQLConf .MAX_CNF_NODE_COUNT .key}=0 " ) {
1371
1383
val x = testRelation.subquery(' x )
1372
1384
val y = testRelation.subquery(' y )
@@ -1384,7 +1396,7 @@ class FilterPushdownSuite extends PlanTest {
1384
1396
(testRelation.subquery(' x ), testRelation.subquery(' y ))
1385
1397
} else {
1386
1398
(testRelation.subquery(' x ),
1387
- testRelation.where(( ' c <= 5 || ' c < 1 ) && ( ' c <= 5 || ' a > 2 )).subquery(' y ))
1399
+ testRelation.where(' c <= 5 || ( ' a > 2 && ' c < 1 )).subquery(' y ))
1388
1400
}
1389
1401
val correctAnswer = left.join(right, condition = Some (" x.b" .attr === " y.b" .attr
1390
1402
&& (((" x.a" .attr > 3 ) && (" x.a" .attr < 13 ) && (" y.c" .attr <= 5 ))
0 commit comments