diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java index 55e24c037c9755..2dc64ccfeabb33 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java @@ -143,8 +143,9 @@ protected List rewriteExpression(List sou targetTopExpressions, targetStructInfo.getOriginalPlan(), Sets.newHashSet(), Sets.newHashSet()); SlotMapping sourceToTargetSlotMapping = SlotMapping.generate(sourceToTargetMapping); // mv sql plan expressions transform to query based - List queryBasedExpressions = ExpressionUtils.permute(shuttledTargetExpressions, - sourceToTargetSlotMapping.inverse()); + List 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 diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/SlotMapping.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/SlotMapping.java index d8ce5e624ff6f6..520d6be9cdd047 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/SlotMapping.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/SlotMapping.java @@ -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; @@ -31,18 +32,19 @@ */ public class SlotMapping extends Mapping { - private final BiMap relationSlotMap; + private final BiMap slotMapping; - public SlotMapping(BiMap relationSlotMap) { - this.relationSlotMap = relationSlotMap; + public SlotMapping(BiMap slotMapping) { + this.slotMapping = slotMapping; } - public BiMap getRelationSlotMap() { - return relationSlotMap; + public BiMap 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 relationSlotMap) { @@ -72,4 +74,11 @@ public static SlotMapping generate(RelationMapping relationMapping) { } return SlotMapping.of(relationSlotMap); } + + /** + * SlotMapping, getSlotMap + */ + public Map getSlotMap() { + return (Map) this.getSlotBiMap(); + } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MappingTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MappingTest.java index e03228524331b1..39f6033b4a72d1 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MappingTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MappingTest.java @@ -288,7 +288,7 @@ private void assertRelationMapping(RelationMapping relationMapping, SlotMapping slotMapping = SlotMapping.generate(relationMapping); Assertions.assertNotNull(slotMapping); BiMap generatedSlotMapping = HashBiMap.create(); - slotMapping.getRelationSlotMap().forEach((key, value) -> + slotMapping.getSlotBiMap().forEach((key, value) -> generatedSlotMapping.put(key.getExprId(), value.getExprId()) ); Assertions.assertEquals(generatedSlotMapping, expectSlotMapping);