Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 48 additions & 44 deletions axiom/optimizer/tests/SubqueryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ TEST_P(SubqueryTest, correlatedIn) {

SCOPED_TRACE(query);
auto plan = toSingleNodePlan(query);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}

// Find customers with no orders.
Expand All @@ -581,7 +581,7 @@ TEST_P(SubqueryTest, correlatedIn) {

SCOPED_TRACE(query);
auto plan = toSingleNodePlan(query);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}

// Correlated IN subquery with non-equality filter in the SELECT list produces
Expand Down Expand Up @@ -851,7 +851,7 @@ TEST_P(SubqueryTest, correlatedProject) {

SCOPED_TRACE(query);
auto plan = toSingleNodePlan(query);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}

// Correlated scalar subquery in projection with SUM aggregation.
Expand All @@ -868,7 +868,7 @@ TEST_P(SubqueryTest, correlatedProject) {

SCOPED_TRACE(query);
auto plan = toSingleNodePlan(query);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}

// Multiple scalar subqueries in projection.
Expand Down Expand Up @@ -911,7 +911,7 @@ TEST_P(SubqueryTest, correlatedProject) {

SCOPED_TRACE(query);
auto plan = toSingleNodePlan(query);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}

// Correlated IN <subquery> in projection.
Expand All @@ -933,7 +933,7 @@ TEST_P(SubqueryTest, correlatedProject) {

SCOPED_TRACE(query);
auto plan = toSingleNodePlan(query);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}

// Correlated NOT IN <subquery> in projection.
Expand All @@ -955,7 +955,7 @@ TEST_P(SubqueryTest, correlatedProject) {

SCOPED_TRACE(query);
auto plan = toSingleNodePlan(query);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}
}

Expand Down Expand Up @@ -1123,31 +1123,34 @@ TEST_P(SubqueryTest, enforceSingleRow) {
auto logicalPlan = parseSelect(query);

{
auto matcher =
matchHiveScan("region")
.nestedLoopJoin(matchHiveScan("nation").enforceSingleRow())
.filter()
.project()
.build();
auto matcher = matchHiveScan("region")
.nestedLoopJoin(
matchHiveScan("nation").enforceSingleRow(),
core::JoinType::kInner,
"gt(r_regionkey, n_regionkey)")
.build();

auto plan = toSingleNodePlan(logicalPlan);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN_V2(plan, matcher);

VELOX_ASSERT_THROW(runVelox(plan), "Expected single row of input.");
}

{
auto matcher =
matchHiveScan("region")
.nestedLoopJoin(
matchHiveScan("nation").gather().enforceSingleRow().broadcast())
.filter()
.project()
.gather()
.build();
auto matcher = matchHiveScan("region")
.nestedLoopJoin(
matchHiveScan("nation")
.gather()
.localPartition()
.enforceSingleRow()
.broadcast(),
core::JoinType::kInner,
"gt(r_regionkey, n_regionkey)")
.gather()
.build();

auto distributedPlan = planVelox(logicalPlan);
AXIOM_ASSERT_DISTRIBUTED_PLAN_V1(distributedPlan.plan, matcher);
AXIOM_ASSERT_DISTRIBUTED_PLAN_V2(distributedPlan.plan, matcher);
}
}

Expand All @@ -1158,32 +1161,33 @@ TEST_P(SubqueryTest, enforceSingleRowInProjection) {
auto logicalPlan = parseSelect(query);

{
auto matcher = core::PlanMatcherBuilder()
.hiveScan("region", test::eq("r_name", "AFRICA"))
.enforceSingleRow()
.nestedLoopJoin(matchHiveScan("nation"))
auto matcher = matchHiveScan("nation")
.nestedLoopJoin(
matchHiveScan("region", test::eq("r_name", "AFRICA"))
.enforceSingleRow())
.build();

auto plan = toSingleNodePlan(logicalPlan);
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN_V2(plan, matcher);
}

{
// TODO: Plan has an extra fragment and an extra shuffle. A
// broadcast-then-EnforceSingleRow shape would collapse the gather
// + broadcast pair into a single broadcast with EnforceSingleRow
// running on each consumer.
auto matcher =
core::PlanMatcherBuilder()
.hiveScan("region", test::eq("r_name", "AFRICA"))
.gather()
.enforceSingleRow()
.nestedLoopJoin(
core::PlanMatcherBuilder().tableScan("nation").broadcast())
.build();
auto matcher = matchHiveScan("nation")
.nestedLoopJoin(
matchHiveScan("region", test::eq("r_name", "AFRICA"))
.gather()
.localPartition()
.enforceSingleRow()
.broadcast())
.gather()
.build();

auto distributedPlan = planVelox(logicalPlan);
AXIOM_ASSERT_DISTRIBUTED_PLAN_V1(distributedPlan.plan, matcher);
AXIOM_ASSERT_DISTRIBUTED_PLAN_V2(distributedPlan.plan, matcher);
}
}

Expand Down Expand Up @@ -1657,7 +1661,7 @@ TEST_P(SubqueryTest, correlatedScalarWithoutAggregation) {
.build();

auto plan = toSingleNodePlan(parseSelect(query, kTestConnectorId));
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}

{
Expand All @@ -1672,7 +1676,7 @@ TEST_P(SubqueryTest, correlatedScalarWithoutAggregation) {
.build();

auto plan = toSingleNodePlan(parseSelect(query, kTestConnectorId));
AXIOM_ASSERT_PLAN_V1(plan, matcher);
AXIOM_ASSERT_PLAN(plan, matcher);
}

// Non-equi correlation: d < b.
Expand Down Expand Up @@ -1880,7 +1884,7 @@ TEST_P(SubqueryTest, leftJoinOnSubquery) {
core::JoinType::kLeft)
.build();

AXIOM_ASSERT_PLAN_V1(toSingleNodePlan(query), matcher);
AXIOM_ASSERT_PLAN(toSingleNodePlan(query), matcher);
}

// Uncorrelated scalar subquery in LEFT JOIN ON clause.
Expand Down Expand Up @@ -1926,7 +1930,7 @@ TEST_P(SubqueryTest, leftJoinOnSubquery) {
core::JoinType::kLeft)
.build();

AXIOM_ASSERT_PLAN_V1(toSingleNodePlan(query), matcher);
AXIOM_ASSERT_PLAN(toSingleNodePlan(query), matcher);
}

// All conjuncts contain subqueries (no non-subquery condition remains).
Expand All @@ -1945,7 +1949,7 @@ TEST_P(SubqueryTest, leftJoinOnSubquery) {
core::JoinType::kLeft)
.build();

AXIOM_ASSERT_PLAN_V1(toSingleNodePlan(query), matcher);
AXIOM_ASSERT_PLAN(toSingleNodePlan(query), matcher);
}

// Correlated EXISTS referencing the right (null-supplying) side.
Expand All @@ -1964,7 +1968,7 @@ TEST_P(SubqueryTest, leftJoinOnSubquery) {
core::JoinType::kLeft)
.build();

AXIOM_ASSERT_PLAN_V1(toSingleNodePlan(query), matcher);
AXIOM_ASSERT_PLAN(toSingleNodePlan(query), matcher);
}

// Correlated NOT EXISTS referencing the right (null-supplying) side.
Expand All @@ -1986,7 +1990,7 @@ TEST_P(SubqueryTest, leftJoinOnSubquery) {
core::JoinType::kLeft)
.build();

AXIOM_ASSERT_PLAN_V1(toSingleNodePlan(query), matcher);
AXIOM_ASSERT_PLAN(toSingleNodePlan(query), matcher);
}

// Correlated scalar subquery referencing the right (null-supplying) side.
Expand Down
Loading