englefly commented on code in PR #64849:
URL: https://github.com/apache/doris/pull/64849#discussion_r3639537587
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/RewriteCteChildren.java:
##########
@@ -113,10 +119,92 @@ public Plan visitLogicalCTEAnchor(LogicalCTEAnchor<?
extends Plan, ? extends Pla
if (cteConsumers.isEmpty()) {
return outer;
}
+ // Save original producer output before rewrite, to detect ExprId
changes
+ // caused by rules like EliminateGroupByKey that wrap slots with
any_value().
+ List<Slot> oldProducerOutput = cteAnchor.child(0).getOutput();
Plan producer = cteAnchor.child(0).accept(this, cascadesContext);
+ outer = syncCteConsumerSlotMaps(oldProducerOutput,
producer.getOutput(),
+ cteAnchor.getCteId(), outer, cascadesContext);
return cteAnchor.withChildren(producer, outer);
}
+ /**
+ * If the producer rewrite changed output ExprIds (e.g. any_value wrapping
in
+ * EliminateGroupByKey), update CTEConsumer slot maps in the consumer tree
to match.
+ *
+ * @return the consumer tree, updated if any producer ExprIds changed
+ */
+ private LogicalPlan syncCteConsumerSlotMaps(List<Slot> oldProducerOutput,
List<Slot> newProducerOutput,
+ CTEId cteId, LogicalPlan outer, CascadesContext cascadesContext) {
+ if (oldProducerOutput.size() != newProducerOutput.size()) {
+ return outer;
+ }
+ Map<ExprId, ExprId> exprIdReplaceMap = new HashMap<>();
+ for (int i = 0; i < oldProducerOutput.size(); i++) {
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]