Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public List<Rule> buildRules() {
.forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));
bottomJoin.getOtherJoinConjuncts()
.forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));
bottomJoin.getMarkJoinConjuncts()
.forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));
Plan newBottomJoin = topJoin.withChildrenNoContext(a, c, null);
Plan left = CBOUtils.newProject(topUsedExprIds, newBottomJoin);
Plan right = CBOUtils.newProjectIfNeeded(topUsedExprIds, b);
Expand Down Expand Up @@ -100,6 +102,8 @@ public List<Rule> buildRules() {
.forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));
bottomJoin.getOtherJoinConjuncts()
.forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));
bottomJoin.getMarkJoinConjuncts()
.forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));
Plan newBottomJoin = topJoin.withChildrenNoContext(a, b, null);
Plan left = CBOUtils.newProject(topUsedExprIds, newBottomJoin);
Plan right = CBOUtils.newProjectIfNeeded(topUsedExprIds, c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public Rule build() {
topProject.getProjects().forEach(expr -> topUsedExprIds.addAll(expr.getInputSlotExprIds()));
bottomSemi.getHashJoinConjuncts().forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));
bottomSemi.getOtherJoinConjuncts().forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));
bottomSemi.getMarkJoinConjuncts().forEach(e -> topUsedExprIds.addAll(e.getInputSlotExprIds()));

Plan left = CBOUtils.newProject(topUsedExprIds, newBottomSemi);
Plan right = CBOUtils.newProjectIfNeeded(topUsedExprIds, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,28 @@ public void generateTopProject() {
)
);
}

@Test
public void generateTopProjectMarkJoin() {
LogicalPlan topJoin1 = new LogicalPlanBuilder(scan1)
.markJoinWithMarkConjuncts(scan2, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 0)) // t1.id = t2.id
.project(ImmutableList.of(1))
.join(scan3, JoinType.INNER_JOIN, Pair.of(0, 0)) // t1.id = t3.id
.project(ImmutableList.of(0))
.build();

PlanChecker.from(MemoTestUtils.createConnectContext(), topJoin1)
.applyExploration(LogicalJoinSemiJoinTransposeProject.INSTANCE.buildRules())
.matchesExploration(
logicalProject(
leftSemiLogicalJoin(
logicalProject(innerLogicalJoin(
logicalOlapScan().when(scan -> scan.getTable().getName().equals("t1")),
logicalOlapScan().when(scan -> scan.getTable().getName().equals("t3"))
)),
logicalProject(logicalOlapScan().when(scan -> scan.getTable().getName().equals("t2")))
)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public void testSemiProjectSemiCommute() {
@Test
public void testSemiProjectSemiCommuteMarkJoin() {
LogicalPlan topJoin = new LogicalPlanBuilder(scan1)
.markJoin(scan2, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 0))
.markJoinWithMarkConjuncts(scan2, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 0))
.project(ImmutableList.of(0, 2))
.markJoin(scan3, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 1))
.projectAll()
.markJoinWithMarkConjuncts(scan3, JoinType.LEFT_SEMI_JOIN, Pair.of(0, 1))
.project(ImmutableList.of(1, 2))
.build();
PlanChecker.from(MemoTestUtils.createConnectContext(), topJoin)
.applyExploration(SemiJoinSemiJoinTransposeProject.INSTANCE.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ public LogicalPlanBuilder markJoin(LogicalPlan right, JoinType joinType, Pair<In
return from(join);
}

public LogicalPlanBuilder markJoinWithMarkConjuncts(LogicalPlan right, JoinType joinType, Pair<Integer, Integer> hashOnSlots) {
ImmutableList<EqualTo> markConjuncts = ImmutableList.of(
new EqualTo(this.plan.getOutput().get(hashOnSlots.first), right.getOutput().get(hashOnSlots.second)));

LogicalJoin<LogicalPlan, LogicalPlan> join = new LogicalJoin<>(joinType, Collections.emptyList(),
Collections.emptyList(), new ArrayList<>(markConjuncts),
new DistributeHint(DistributeType.NONE), Optional.of(new MarkJoinSlotReference("fake")),
this.plan, right, null);
return from(join);
}

public LogicalPlanBuilder join(LogicalPlan right, JoinType joinType, Pair<Integer, Integer> hashOnSlots) {
ImmutableList<EqualTo> hashConjuncts = ImmutableList.of(
new EqualTo(this.plan.getOutput().get(hashOnSlots.first), right.getOutput().get(hashOnSlots.second)));
Expand Down