github-actions[bot] commented on code in PR #64900:
URL: https://github.com/apache/doris/pull/64900#discussion_r3481013647


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownTopNDistinctThroughUnion.java:
##########
@@ -63,23 +64,23 @@ public class PushDownTopNDistinctThroughUnion implements 
RewriteRuleFactory {
     public List<Rule> buildRules() {
         return ImmutableList.of(
                 logicalTopN(logicalAggregate(logicalUnion().when(union -> 
union.getQualifier() == Qualifier.ALL))
-                        .when(agg -> agg.isDistinct()))
+                        .when(Aggregate::isDistinct))
                         .then(topN -> {
                             LogicalAggregate<LogicalUnion> agg = topN.child();
                             LogicalUnion union = agg.child();
                             List<Plan> newChildren = new ArrayList<>();
-                            for (Plan child : union.children()) {
+                            for (int i = 0; i < union.arity(); ++i) {
                                 Map<Expression, Expression> replaceMap = new 
HashMap<>();
-                                for (int i = 0; i < union.getOutputs().size(); 
++i) {
-                                    NamedExpression output = 
union.getOutputs().get(i);
-                                    replaceMap.put(output, 
child.getOutput().get(i));
+                                for (int j = 0; j < union.getOutputs().size(); 
++j) {
+                                    NamedExpression output = 
union.getOutputs().get(j);

Review Comment:
   This fixes the TopN variant, but the parallel LIMIT-only path still has the 
same output mapping bug. `BuildAggForUnion` rewrites `UNION DISTINCT` into a 
distinct `LogicalAggregate` over `union.withAllQualifier()`, and a query with 
`... LIMIT 10` but no outer `ORDER BY` reaches 
`PushDownLimitDistinctThroughUnion` instead of this TopN rule. That rule still 
loops over `union.getOutputs().size()` and reads `child.getOutput().get(i)`, so 
the duplicate-column/window shape added in this PR can still index past the 
pruned child output on the LIMIT-only path. Please apply the same 
`union.getRegularChildOutput(childIdx)` mapping in 
`PushDownLimitDistinctThroughUnion` and add a no-ORDER-BY LIMIT case.



-- 
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]

Reply via email to