Skip to content

Commit

Permalink
[refactor] (Nereids) rename GroupExpression.getParent() to getOwnerGr…
Browse files Browse the repository at this point in the history
…oup() (#11027)

GroupExpression.getParent() returns the group which contains this expr. This name is missleading especially in tree structures.
So we change the name to getOwnerGroup.
  • Loading branch information
englefly authored Jul 20, 2022
1 parent a1c1cfc commit 6233b52
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void execute() throws AnalysisException {
List<Plan> newPlans = rule.transform(plan, context.getPlannerContext());
for (Plan newPlan : newPlans) {
GroupExpression newGroupExpression = context.getPlannerContext().getMemo()
.copyIn(newPlan, groupExpression.getParent(), rule.isRewrite());
.copyIn(newPlan, groupExpression.getOwnerGroup(), rule.isRewrite());
if (newPlan instanceof LogicalPlan) {
pushTask(new DeriveStatsJob(newGroupExpression, context));
if (exploredOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void execute1() {
}
PlanContext planContext = new PlanContext(groupExpression);
// TODO: calculate stats.
groupExpression.getParent().setStatistics(planContext.getStatistics());
groupExpression.getOwnerGroup().setStatistics(planContext.getStatistics());

enforce(outputProperty, childrenInputProperties);
}
Expand Down Expand Up @@ -193,7 +193,7 @@ private void enforce(PhysicalProperties outputProperty, List<PhysicalProperties>

// enforcedProperty is superset of requiredProperty
if (!addEnforcedProperty.equals(requiredProperties)) {
putProperty(groupExpression.getParent().getBestExpression(addEnforcedProperty),
putProperty(groupExpression.getOwnerGroup().getBestExpression(addEnforcedProperty),
requiredProperties, requiredProperties, Lists.newArrayList(outputProperty));
}
} else {
Expand All @@ -217,7 +217,7 @@ private void putProperty(GroupExpression groupExpression,
// and shuffle join two types outputProperty.
groupExpression.putOutputPropertiesMap(outputProperty, requiredProperty);
}
this.groupExpression.getParent().setBestPlan(groupExpression,
this.groupExpression.getOwnerGroup().setBestPlan(groupExpression,
curTotalCost, requiredProperty);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Group(GroupId groupId, GroupExpression groupExpression, LogicalProperties
this.physicalExpressions.add(groupExpression);
}
this.logicalProperties = logicalProperties;
groupExpression.setParent(this);
groupExpression.setOwnerGroup(this);
}

public GroupId getGroupId() {
Expand All @@ -93,7 +93,7 @@ public GroupExpression addGroupExpression(GroupExpression groupExpression) {
} else {
physicalExpressions.add(groupExpression);
}
groupExpression.setParent(this);
groupExpression.setOwnerGroup(this);
return groupExpression;
}

Expand All @@ -109,7 +109,7 @@ public GroupExpression removeGroupExpression(GroupExpression groupExpression) {
} else {
physicalExpressions.remove(groupExpression);
}
groupExpression.setParent(null);
groupExpression.setOwnerGroup(null);
return groupExpression;
}

Expand All @@ -121,7 +121,7 @@ public GroupExpression removeGroupExpression(GroupExpression groupExpression) {
*/
public GroupExpression rewriteLogicalExpression(GroupExpression newExpression,
LogicalProperties logicalProperties) {
newExpression.setParent(this);
newExpression.setOwnerGroup(this);
this.logicalProperties = logicalProperties;
GroupExpression oldExpression = getLogicalExpression();
logicalExpressions.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* Representation for group expression in cascades optimizer.
*/
public class GroupExpression {
private Group parent;
private Group ownerGroup;
private List<Group> children;
private final Plan plan;
private final BitSet ruleMasks;
Expand Down Expand Up @@ -81,12 +81,12 @@ public void addChild(Group child) {
children.add(child);
}

public Group getParent() {
return parent;
public Group getOwnerGroup() {
return ownerGroup;
}

public void setParent(Group parent) {
this.parent = parent;
public void setOwnerGroup(Group ownerGroup) {
this.ownerGroup = ownerGroup;
}

public Plan getPlan() {
Expand Down
18 changes: 9 additions & 9 deletions fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Memo {
private Group root;

public Memo(Plan plan) {
root = copyIn(plan, null, false).getParent();
root = copyIn(plan, null, false).getOwnerGroup();
}

public Group getRoot() {
Expand Down Expand Up @@ -82,9 +82,9 @@ public GroupExpression copyIn(Plan node, @Nullable Group target, boolean rewrite
if (child instanceof GroupPlan) {
childrenGroups.add(((GroupPlan) child).getGroup());
} else if (child.getGroupExpression().isPresent()) {
childrenGroups.add(child.getGroupExpression().get().getParent());
childrenGroups.add(child.getGroupExpression().get().getOwnerGroup());
} else {
childrenGroups.add(copyIn(child, null, rewrite).getParent());
childrenGroups.add(copyIn(child, null, rewrite).getOwnerGroup());
}
}
node = replaceChildrenToGroupPlan(node, childrenGroups);
Expand Down Expand Up @@ -133,9 +133,9 @@ private GroupExpression insertOrRewriteGroupExpression(GroupExpression groupExpr
boolean rewrite, LogicalProperties logicalProperties) {
GroupExpression existedGroupExpression = groupExpressions.get(groupExpression);
if (existedGroupExpression != null
&& existedGroupExpression.getParent().getLogicalProperties().equals(logicalProperties)) {
if (target != null && !target.getGroupId().equals(existedGroupExpression.getParent().getGroupId())) {
mergeGroup(target, existedGroupExpression.getParent());
&& existedGroupExpression.getOwnerGroup().getLogicalProperties().equals(logicalProperties)) {
if (target != null && !target.getGroupId().equals(existedGroupExpression.getOwnerGroup().getGroupId())) {
mergeGroup(target, existedGroupExpression.getOwnerGroup());
}
return existedGroupExpression;
}
Expand Down Expand Up @@ -172,7 +172,7 @@ private void mergeGroup(Group source, Group destination) {
List<GroupExpression> needReplaceChild = Lists.newArrayList();
groupExpressions.values().forEach(groupExpression -> {
if (groupExpression.children().contains(source)) {
if (groupExpression.getParent().equals(destination)) {
if (groupExpression.getOwnerGroup().equals(destination)) {
// cycle, we should not merge
return;
}
Expand All @@ -190,7 +190,7 @@ private void mergeGroup(Group source, Group destination) {
}
if (groupExpressions.containsKey(groupExpression)) {
// TODO: need to merge group recursively
groupExpression.getParent().removeGroupExpression(groupExpression);
groupExpression.getOwnerGroup().removeGroupExpression(groupExpression);
} else {
groupExpressions.put(groupExpression, groupExpression);
}
Expand All @@ -210,7 +210,7 @@ private void mergeGroup(Group source, Group destination) {
* Add enforcer expression into the target group.
*/
public void addEnforcerPlan(GroupExpression groupExpression, Group group) {
groupExpression.setParent(group);
groupExpression.setOwnerGroup(group);
}

private Plan replaceChildrenToGroupPlan(Plan plan, List<Group> childrenGroups) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void assembleAllCombinationPlanTree(Plan root, Pattern<Plan> rootPattern
children.add(childrenPlans.get(i).get(childrenPlanIndex[i]));
}

LogicalProperties logicalProperties = groupExpression.getParent().getLogicalProperties();
LogicalProperties logicalProperties = groupExpression.getOwnerGroup().getLogicalProperties();
// assemble children: replace GroupPlan to real plan,
// withChildren will erase groupExpression, so we must
// withGroupExpression too.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private PhysicalProperties enforceSort(PhysicalProperties oldOutputProperty) {
oldOutputProperty.getOrderSpec());
newOutputProperty.setOrderSpec(context.getRequiredProperties().getOrderSpec());
GroupExpression enforcer =
context.getRequiredProperties().getOrderSpec().addEnforcer(groupExpression.getParent());
context.getRequiredProperties().getOrderSpec().addEnforcer(groupExpression.getOwnerGroup());

updateCostWithEnforcer(enforcer, oldOutputProperty, newOutputProperty);

Expand All @@ -89,7 +89,7 @@ private PhysicalProperties enforceDistribution(PhysicalProperties oldOutputPrope
oldOutputProperty.getOrderSpec());
newOutputProperty.setDistributionSpec(context.getRequiredProperties().getDistributionSpec());
GroupExpression enforcer =
context.getRequiredProperties().getDistributionSpec().addEnforcer(groupExpression.getParent());
context.getRequiredProperties().getDistributionSpec().addEnforcer(groupExpression.getOwnerGroup());

updateCostWithEnforcer(enforcer, oldOutputProperty, newOutputProperty);

Expand All @@ -99,13 +99,13 @@ private PhysicalProperties enforceDistribution(PhysicalProperties oldOutputPrope
private void updateCostWithEnforcer(GroupExpression enforcer,
PhysicalProperties oldOutputProperty,
PhysicalProperties newOutputProperty) {
context.getPlannerContext().getMemo().addEnforcerPlan(enforcer, groupExpression.getParent());
context.getPlannerContext().getMemo().addEnforcerPlan(enforcer, groupExpression.getOwnerGroup());
curTotalCost += CostCalculator.calculateCost(enforcer);

if (enforcer.updateLowestCostTable(newOutputProperty, Lists.newArrayList(oldOutputProperty), curTotalCost)) {
enforcer.putOutputPropertiesMap(newOutputProperty, newOutputProperty);
}
groupExpression.getParent().setBestPlan(enforcer, curTotalCost, newOutputProperty);
groupExpression.getOwnerGroup().setBestPlan(enforcer, curTotalCost, newOutputProperty);
}

private PhysicalProperties enforceSortAndDistribution(PhysicalProperties outputProperty,
Expand Down

0 comments on commit 6233b52

Please sign in to comment.