diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCTEConsumer.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCTEConsumer.java index 97ea18600c..9c0996a2c3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCTEConsumer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCTEConsumer.java @@ -22,6 +22,7 @@ import org.apache.doris.nereids.properties.LogicalProperties; import org.apache.doris.nereids.trees.expressions.CTEId; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.expressions.SlotReference; +import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator; import org.apache.doris.nereids.trees.plans.BlockFuncDepsPropagation; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.PlanType; @@ -93,8 +94,13 @@ public class LogicalCTEConsumer extends LogicalRelation implements BlockFuncDeps private void initOutputMaps(LogicalPlan childPlan) { List producerOutput = childPlan.getOutput(); for (Slot producerOutputSlot : producerOutput) { - Slot consumerSlot = new SlotReference(producerOutputSlot.getName(), - producerOutputSlot.getDataType(), producerOutputSlot.nullable(), ImmutableList.of(name)); + SlotReference slotRef = + producerOutputSlot instanceof SlotReference ? (SlotReference) producerOutputSlot : null; + Slot consumerSlot = new SlotReference(StatementScopeIdGenerator.newExprId(), + producerOutputSlot.getName(), producerOutputSlot.getDataType(), + producerOutputSlot.nullable(), ImmutableList.of(name), + slotRef != null ? (slotRef.getColumn().isPresent() ? slotRef.getColumn().get() : null) : null, + slotRef != null ? Optional.of(slotRef.getInternalName()) : Optional.empty()); producerToConsumerOutputMap.put(producerOutputSlot, consumerSlot); consumerToProducerOutputMap.put(consumerSlot, producerOutputSlot); }