You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/12/30 03:57:02 UTC

[GitHub] [doris] englefly commented on a diff in pull request #15240: [fix](nereids) binding priority in BindSlotReference::bindSortWithAggregateFunction()

englefly commented on code in PR #15240:
URL: https://github.com/apache/doris/pull/15240#discussion_r1059232132


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -373,13 +374,45 @@ private Plan bindSortWithAggregateFunction(
             LogicalSort<? extends Plan> sort, Aggregate<? extends Plan> aggregate, CascadesContext ctx) {
         // We should deduplicate the slots, otherwise the binding process will fail due to the
         // ambiguous slots exist.
-        Set<Slot> boundSlots = Stream.concat(Stream.of(aggregate), aggregate.children().stream())
-                .flatMap(plan -> plan.getOutput().stream())
-                .collect(Collectors.toSet());
+        //Set<Slot> boundSlots = Stream.concat(Stream.of(aggregate), aggregate.children().stream())
+        //        .flatMap(plan -> plan.getOutput().stream())
+        //        .collect(Collectors.toSet());
+        //List<OrderKey> sortItemList = sort.getOrderKeys()
+        //        .stream()
+        //        .map(orderKey -> {
+        //            Expression item = new SlotBinder(toScope(new ArrayList<>(boundSlots)), sort, ctx)
+        //                    .bind(orderKey.getExpr());
+        //            return new OrderKey(item, orderKey.isAsc(), orderKey.isNullFirst());
+        //        }).collect(Collectors.toList());
+        //return new LogicalSort<>(sortItemList, sort.child());
+        //try bound order key with agg output, if failed, try to bound with output of agg.child
+        //example:
+        //        select
+        //        col1 * -1 as col1    # inner_col1 * -1 as alias_col1
+        //        from
+        //                (
+        //                        select 1 as col1
+        //                        union
+        //                        select -2 as col1
+        //                ) t
+        //        group by col1
+        //        order by col1;     # order by order_col1
+        // bind order_col1 with alias_col1, then, bind it with inner_col1
+        List<Slot> boundSlots = Lists.newArrayList();
+        Set<String> slotNames = new HashSet<>();
+
+        Stream.concat(Stream.of(aggregate), aggregate.children().stream())
+                .flatMap(plan -> plan.getOutput().stream()).forEach(slot -> {
+                    if (!slotNames.contains(slot.getName())) {
+                        slotNames.add(slot.getName());
+                        boundSlots.add(slot);
+                    }
+                });

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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org