Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
keanji-x committed Jun 28, 2024
1 parent 98c256a commit a078836
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Represents a direct graph where each node corresponds to a set of slots in a table,
Expand Down Expand Up @@ -71,9 +70,11 @@ public DGItem(DGItem dgItem) {
}

public void replace(Map<Slot, Slot> replaceMap) {
this.slots = this.slots.stream()
.map(s -> replaceMap.getOrDefault(s, s))
.collect(Collectors.toSet());
Set<Slot> newSlots = new HashSet<>();
for (Slot slot : slots) {
newSlots.add(replaceMap.getOrDefault(slot, slot));
}
this.slots = newSlots;
}
}

Expand Down Expand Up @@ -177,9 +178,10 @@ public void replace(Map<Slot, Slot> replaceSlotMap) {
}
Map<Set<Slot>, Integer> newItemMap = new HashMap<>();
for (Entry<Set<Slot>, Integer> e : itemMap.entrySet()) {
Set<Slot> key = e.getKey().stream()
.map(s -> replaceSlotMap.getOrDefault(s, s))
.collect(Collectors.toSet());
Set<Slot> key = new HashSet<>();
for (Slot slot : e.getKey()) {
key.add(replaceSlotMap.getOrDefault(slot, slot));
}
newItemMap.put(key, e.getValue());
}
this.itemMap = newItemMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,62 +132,42 @@ public ImmutableSet<FdItem> computeFdItems() {
return builder.build();
}

@Override
public void computeUnique(Builder builder) {
builder.addUniqueSlot(child(0).getLogicalProperties().getTrait());
if (qualifier == Qualifier.DISTINCT) {
builder.addUniqueSlot(ImmutableSet.copyOf(getOutput()));
}
Map<Slot, Slot> constructReplaceMapForChild(int index) {
Map<Slot, Slot> replaceMap = new HashMap<>();
List<Slot> output = getOutput();
List<? extends Slot> originalOutputs = regularChildrenOutputs.isEmpty()
? child(0).getOutput()
: regularChildrenOutputs.get(0);
? child(index).getOutput()
: regularChildrenOutputs.get(index);
for (int i = 0; i < output.size(); i++) {
replaceMap.put(originalOutputs.get(i), output.get(i));
}
builder.replaceUniqueBy(replaceMap);
return replaceMap;
}

@Override
public void computeUnique(Builder builder) {
builder.addUniqueSlot(child(0).getLogicalProperties().getTrait());
if (qualifier == Qualifier.DISTINCT) {
builder.addUniqueSlot(ImmutableSet.copyOf(getOutput()));
}
builder.replaceUniqueBy(constructReplaceMapForChild(0));
}

@Override
public void computeEqualSet(DataTrait.Builder builder) {
builder.addEqualSet(child(0).getLogicalProperties().getTrait());
Map<Slot, Slot> replaceMap = new HashMap<>();
List<Slot> output = getOutput();
List<? extends Slot> originalOutputs = regularChildrenOutputs.isEmpty()
? child(0).getOutput()
: regularChildrenOutputs.get(0);
for (int i = 0; i < output.size(); i++) {
replaceMap.put(originalOutputs.get(i), output.get(i));
}
builder.replaceEqualSetBy(replaceMap);
builder.replaceEqualSetBy(constructReplaceMapForChild(0));
}

@Override
public void computeFd(DataTrait.Builder builder) {
builder.addFuncDepsDG(child(0).getLogicalProperties().getTrait());
Map<Slot, Slot> replaceMap = new HashMap<>();
List<Slot> output = getOutput();
List<? extends Slot> originalOutputs = regularChildrenOutputs.isEmpty()
? child(0).getOutput()
: regularChildrenOutputs.get(0);
for (int i = 0; i < output.size(); i++) {
replaceMap.put(originalOutputs.get(i), output.get(i));
}
builder.replaceFuncDepsBy(replaceMap);
builder.replaceFuncDepsBy(constructReplaceMapForChild(0));
}

@Override
public void computeUniform(Builder builder) {
builder.addUniformSlot(child(0).getLogicalProperties().getTrait());
Map<Slot, Slot> replaceMap = new HashMap<>();
List<Slot> output = getOutput();
List<? extends Slot> originalOutputs = regularChildrenOutputs.isEmpty()
? child(0).getOutput()
: regularChildrenOutputs.get(0);
for (int i = 0; i < output.size(); i++) {
replaceMap.put(originalOutputs.get(i), output.get(i));
}
builder.replaceUniformBy(replaceMap);
builder.replaceUniformBy(constructReplaceMapForChild(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.doris.nereids.trees.plans.logical;

import org.apache.doris.nereids.memo.GroupExpression;
import org.apache.doris.nereids.properties.DataTrait;
import org.apache.doris.nereids.properties.DataTrait.Builder;
import org.apache.doris.nereids.properties.ExprFdItem;
import org.apache.doris.nereids.properties.FdFactory;
Expand Down Expand Up @@ -109,15 +108,10 @@ public LogicalIntersect withNewOutputs(List<NamedExpression> newOutputs) {
Optional.empty(), Optional.empty(), children);
}

void replaceSlotInFuncDeps(DataTrait.Builder builder,
List<Slot> originalOutputs, List<Slot> newOutputs) {

}

Map<Slot, Slot> constructReplaceMap() {
Map<Slot, Slot> replaceMap = new HashMap<>();
for (int i = 0; i < children.size(); i++) {
List<? extends Slot> originOutputs = this.regularChildrenOutputs.isEmpty()
List<? extends Slot> originOutputs = this.regularChildrenOutputs.size() == children.size()
? child(i).getOutput()
: regularChildrenOutputs.get(i);
for (int j = 0; j < originOutputs.size(); j++) {
Expand Down

0 comments on commit a078836

Please sign in to comment.