Skip to content

Commit

Permalink
[fix](Nereids) should not push down project to the nullable side of o…
Browse files Browse the repository at this point in the history
…uter join apache#27912 (apache#27913)
  • Loading branch information
starocean999 authored and gnehil committed Dec 4, 2023
1 parent b27e5eb commit cae2a1a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ private Plan pushdownProject(LogicalProject<LogicalJoin<GroupPlan, GroupPlan>> p
return null;
}
// we could not push nullable side project
if ((join.getJoinType().isLeftOuterJoin() && rightContains)
|| (join.getJoinType().isRightOuterJoin() && leftContains)) {
if (((join.getJoinType().isLeftOuterJoin() || join.getJoinType().isFullOuterJoin()) && rightContains)
|| ((join.getJoinType().isRightOuterJoin() || join.getJoinType().isFullOuterJoin()) && leftContains)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,59 @@ public void pushBothSide() {
);
}

@Test
public void pushRightSide() {
// project (t1.id + 1) as alias, t1.name, (t2.id + 1) as alias, t2.name
List<NamedExpression> projectExprs = ImmutableList.of(
new Alias(new Add(scan1.getOutput().get(0), Literal.of(1)), "alias"),
scan1.getOutput().get(1),
scan2.getOutput().get(1)
);
// complex projection contain ti.id, which isn't in Join Condition
LogicalPlan plan = new LogicalPlanBuilder(scan1)
.join(scan2, JoinType.LEFT_OUTER_JOIN, Pair.of(1, 1))
.projectExprs(projectExprs)
.join(scan3, JoinType.INNER_JOIN, Pair.of(1, 1))
.build();

PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
.applyExploration(PushdownProjectThroughInnerOuterJoin.INSTANCE.buildRules())
.printlnOrigin()
.printlnExploration()
.matchesExploration(
logicalJoin(
logicalProject(
logicalJoin(
logicalProject().when(project -> project.getProjects().size() == 2),
logicalOlapScan()
)
),
logicalOlapScan()
)
);
}

@Test
public void pushNoSide() {
// project (t1.id + 1) as alias, t1.name, (t2.id + 1) as alias, t2.name
List<NamedExpression> projectExprs = ImmutableList.of(
new Alias(new Add(scan1.getOutput().get(0), Literal.of(1)), "alias"),
scan1.getOutput().get(1),
scan2.getOutput().get(1)
);
// complex projection contain ti.id, which isn't in Join Condition
LogicalPlan plan = new LogicalPlanBuilder(scan1)
.join(scan2, JoinType.FULL_OUTER_JOIN, Pair.of(1, 1))
.projectExprs(projectExprs)
.join(scan3, JoinType.INNER_JOIN, Pair.of(1, 1))
.build();

int plansNumber = PlanChecker.from(MemoTestUtils.createConnectContext(), plan)
.applyExploration(PushdownProjectThroughInnerOuterJoin.INSTANCE.buildRules())
.plansNumber();
Assertions.assertEquals(1, plansNumber);
}

@Test
public void pushdownProjectInCondition() {
// project (t1.id + 1) as alias, t1.name, (t2.id + 1) as alias, t2.name
Expand Down

0 comments on commit cae2a1a

Please sign in to comment.