Skip to content

Commit fa63eb8

Browse files
fix cte loss
1 parent eb05678 commit fa63eb8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/DecomposeRepeatWithPreAggregation.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ public Plan rewriteRoot(Plan plan, JobContext jobContext) {
100100
return plan;
101101
}
102102

103+
@Override
104+
public Plan visitLogicalCTEAnchor(
105+
LogicalCTEAnchor<? extends Plan, ? extends Plan> anchor, DistinctSelectorContext ctx) {
106+
Plan child1 = anchor.child(0).accept(this, ctx);
107+
DistinctSelectorContext consumerContext =
108+
new DistinctSelectorContext(ctx.statementContext, ctx.cascadesContext);
109+
Plan child2 = anchor.child(1).accept(this, consumerContext);
110+
for (int i = consumerContext.cteProducerList.size() - 1; i >= 0; i--) {
111+
LogicalCTEProducer<? extends Plan> producer = consumerContext.cteProducerList.get(i);
112+
child2 = new LogicalCTEAnchor<>(producer.getCteId(), producer, child2);
113+
}
114+
return anchor.withChildren(ImmutableList.of(child1, child2));
115+
}
116+
103117
@Override
104118
public Plan visitLogicalAggregate(LogicalAggregate<? extends Plan> aggregate, DistinctSelectorContext ctx) {
105119
aggregate = visitChildren(this, aggregate, ctx);

0 commit comments

Comments
 (0)