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 @@ -94,6 +94,18 @@ private void checkUnexpectedExpression(Plan plan) {
}
}

/**
*
* used for test
* after applying a rule, use this method to check whether all slots are from children
*/
public void checkTreeAllSlotReferenceFromChildren(Plan plan) {
checkAllSlotReferenceFromChildren(plan);
for (Plan child : plan.children()) {
checkTreeAllSlotReferenceFromChildren(child);
}
}

private void checkAllSlotReferenceFromChildren(Plan plan) {
Set<Slot> inputSlots = plan.getInputSlots();
RoaringBitmap childrenOutput = plan.getChildrenOutputExprIdBitSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,21 @@ private Plan pushDownAssertNumRowsJoin(LogicalJoin topJoin) {

@VisibleForTesting
LogicalProject<? extends Plan> projectAliasOnPlan(List<Alias> projections, Plan child) {
List<NamedExpression> newProjections = Lists.newArrayList(child.getOutput());
newProjections.addAll(projections);
return new LogicalProject<>(newProjections, child);
if (child instanceof LogicalProject) {
LogicalProject<? extends Plan> project = (LogicalProject<? extends Plan>) child;
List<NamedExpression> newProjections =
Lists.newArrayList(project.getProjects());
for (Alias alias : projections) {
if (!project.getOutput().contains(alias.toSlot())) {
NamedExpression expr = (NamedExpression) project.pushDownExpressionPastProject(alias);
newProjections.add(expr);
}
}
return project.withProjects(newProjections);
} else {
List<NamedExpression> newProjections = Lists.newArrayList(child.getOutput());
newProjections.addAll(projections);
return new LogicalProject<>(newProjections, child);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ void testProjectAliasOnPlan() {
Assertions.assertTrue(newPlan instanceof LogicalProject
&& newPlan.getOutput().size() == 2
&& ((LogicalProject<?>) newPlan).getOutputs().get(0).equals(slot)
&& ((LogicalProject<?>) newPlan).getOutputs().get(1).equals(alias)
&& newPlan.child(0) instanceof LogicalProject);
&& ((LogicalProject<?>) newPlan).getOutputs().get(1).equals(alias));
}
}
Loading