Skip to content

Commit

Permalink
remove repeated method
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Dec 4, 2023
1 parent b92fcab commit e8f1bca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ protected List<NamedExpression> rewriteExpression(List<? extends Expression> sou
targetTopExpressions, targetStructInfo.getOriginalPlan(), Sets.newHashSet(), Sets.newHashSet());
SlotMapping sourceToTargetSlotMapping = SlotMapping.generate(sourceToTargetMapping);
// mv sql plan expressions transform to query based
List<? extends Expression> queryBasedExpressions = ExpressionUtils.permute(shuttledTargetExpressions,
sourceToTargetSlotMapping.inverse());
List<? extends Expression> queryBasedExpressions = ExpressionUtils.replace(
shuttledTargetExpressions.stream().map(Expression.class::cast).collect(Collectors.toList()),
sourceToTargetSlotMapping.inverse().getSlotMap());
// mv sql query based expression and index mapping
ExpressionIndexMapping.generate(queryBasedExpressions);
// TODO visit source expression and replace the expression with expressionIndexMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.doris.nereids.rules.exploration.mv.mapping;

import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.Slot;

import com.google.common.collect.BiMap;
Expand All @@ -31,18 +32,19 @@
*/
public class SlotMapping extends Mapping {

private final BiMap<MappedSlot, MappedSlot> relationSlotMap;
private final BiMap<MappedSlot, MappedSlot> slotMapping;

public SlotMapping(BiMap<MappedSlot, MappedSlot> relationSlotMap) {
this.relationSlotMap = relationSlotMap;
public SlotMapping(BiMap<MappedSlot, MappedSlot> slotMapping) {
this.slotMapping = slotMapping;
}

public BiMap<MappedSlot, MappedSlot> getRelationSlotMap() {
return relationSlotMap;
public BiMap<MappedSlot, MappedSlot> getSlotBiMap() {
return slotMapping;
}

public SlotMapping inverse() {
return SlotMapping.of(relationSlotMap.inverse());
return slotMapping == null
? SlotMapping.of(HashBiMap.create()) : SlotMapping.of(slotMapping.inverse());
}

public static SlotMapping of(BiMap<MappedSlot, MappedSlot> relationSlotMap) {
Expand Down Expand Up @@ -72,4 +74,11 @@ public static SlotMapping generate(RelationMapping relationMapping) {
}
return SlotMapping.of(relationSlotMap);
}

/**
* SlotMapping, getSlotMap
*/
public Map<? extends Expression, ? extends Expression> getSlotMap() {
return (Map) this.getSlotBiMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private void assertRelationMapping(RelationMapping relationMapping,
SlotMapping slotMapping = SlotMapping.generate(relationMapping);
Assertions.assertNotNull(slotMapping);
BiMap<ExprId, ExprId> generatedSlotMapping = HashBiMap.create();
slotMapping.getRelationSlotMap().forEach((key, value) ->
slotMapping.getSlotBiMap().forEach((key, value) ->
generatedSlotMapping.put(key.getExprId(), value.getExprId())
);
Assertions.assertEquals(generatedSlotMapping, expectSlotMapping);
Expand Down

0 comments on commit e8f1bca

Please sign in to comment.