Skip to content

Commit 0dd008b

Browse files
committed
Add Orri tests
1 parent dd9c046 commit 0dd008b

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

axiom/optimizer/tests/PlanTest.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,114 @@ TEST_F(PlanTest, lambdaArgs) {
14271427
AXIOM_ASSERT_PLAN(plan, matcher);
14281428
}
14291429

1430+
TEST_F(PlanTest, joinWithFilterOverLimit) {
1431+
testConnector_->addTable("t", ROW({"a", "b", "c"}, BIGINT()));
1432+
testConnector_->addTable("u", ROW({"x", "y", "z"}, BIGINT()));
1433+
1434+
lp::PlanBuilder::Context ctx(kTestConnectorId);
1435+
auto logicalPlan =
1436+
lp::PlanBuilder(ctx)
1437+
.tableScan("t")
1438+
.limit(100)
1439+
.filter("b > 50")
1440+
.join(
1441+
lp::PlanBuilder(ctx).tableScan("u").limit(50).filter("y < 100"),
1442+
"a = x",
1443+
lp::JoinType::kInner)
1444+
.build();
1445+
1446+
{
1447+
auto plan = toSingleNodePlan(logicalPlan);
1448+
auto matcher = core::PlanMatcherBuilder()
1449+
.tableScan("t")
1450+
.limit()
1451+
.filter("b > 50")
1452+
.hashJoin(
1453+
core::PlanMatcherBuilder()
1454+
.tableScan("u")
1455+
.limit()
1456+
.filter("y < 100")
1457+
.build())
1458+
.build();
1459+
1460+
AXIOM_ASSERT_PLAN(plan, matcher);
1461+
}
1462+
}
1463+
1464+
TEST_F(PlanTest, outerJoinWithInnerJoin) {
1465+
testConnector_->addTable("t", ROW({"a", "b", "c"}, BIGINT()));
1466+
testConnector_->addTable("v", ROW({"vx", "vy", "vz"}, BIGINT()));
1467+
testConnector_->addTable("u", ROW({"x", "y", "z"}, BIGINT()));
1468+
1469+
lp::PlanBuilder::Context ctx(kTestConnectorId);
1470+
auto logicalPlan = lp::PlanBuilder(ctx)
1471+
.tableScan("t")
1472+
.filter("b > 50")
1473+
.join(
1474+
lp::PlanBuilder(ctx).tableScan("u").join(
1475+
lp::PlanBuilder(ctx).tableScan("v"),
1476+
"x = vx",
1477+
lp::JoinType::kInner),
1478+
"a = x",
1479+
lp::JoinType::kLeft)
1480+
.build();
1481+
1482+
{
1483+
SCOPED_TRACE("left join with inner join on right");
1484+
1485+
auto plan = toSingleNodePlan(logicalPlan);
1486+
auto matcher =
1487+
core::PlanMatcherBuilder()
1488+
.tableScan("t")
1489+
.filter("b > 50")
1490+
.hashJoin(
1491+
core::PlanMatcherBuilder()
1492+
.tableScan("u")
1493+
.hashJoin(core::PlanMatcherBuilder().tableScan("v").build())
1494+
1495+
.build())
1496+
.build();
1497+
1498+
AXIOM_ASSERT_PLAN(plan, matcher);
1499+
}
1500+
1501+
logicalPlan = lp::PlanBuilder(ctx)
1502+
.tableScan("t")
1503+
.filter("b > 50")
1504+
.aggregate({"a", "b"}, {"sum(c)"})
1505+
.join(
1506+
lp::PlanBuilder(ctx)
1507+
.tableScan("u")
1508+
.join(
1509+
lp::PlanBuilder(ctx).tableScan("v"),
1510+
"x = vx",
1511+
lp::JoinType::kInner)
1512+
.filter("not(x = vy)"),
1513+
"a = x",
1514+
lp::JoinType::kLeft)
1515+
.build();
1516+
1517+
{
1518+
SCOPED_TRACE("Aggregation left join filter over inner join");
1519+
auto plan = toSingleNodePlan(logicalPlan);
1520+
auto matcher =
1521+
core::PlanMatcherBuilder()
1522+
.tableScan("t")
1523+
.filter()
1524+
.aggregation()
1525+
.hashJoin(
1526+
core::PlanMatcherBuilder()
1527+
.tableScan("u")
1528+
.hashJoin(core::PlanMatcherBuilder().tableScan("v").build())
1529+
.filter()
1530+
.build())
1531+
.project()
1532+
.build();
1533+
1534+
AXIOM_ASSERT_PLAN(plan, matcher);
1535+
}
1536+
}
1537+
14301538
#undef AXIOM_ASSERT_PLAN
14311539

14321540
} // namespace

0 commit comments

Comments
 (0)