morrySnow commented on code in PR #12129:
URL: https://github.com/apache/doris/pull/12129#discussion_r956609185


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -949,4 +958,18 @@ public Expression visitExist(ExistContext context) {
     public List<Expression> withInList(PredicateContext ctx) {
         return 
ctx.expression().stream().map(this::getExpression).collect(ImmutableList.toImmutableList());
     }
+
+    static class SelectQuerySpecificationContext {

Review Comment:
   if u need it, the better way to do this is add a new Rule include 
`whereClause? aggClause? havingClause?` named `SelectQuerySpecification` in 
`DorisParser.g4` 



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -155,9 +157,15 @@ private <E extends Expression> List<E> bind(List<E> 
exprList, List<Plan> inputs,
     }
 
     private <E extends Expression> E bind(E expr, List<Plan> inputs, Plan 
plan, CascadesContext cascadesContext) {
-        List<Slot> boundedSlots = inputs.stream()
-                .flatMap(input -> input.getOutput().stream())
-                .collect(Collectors.toList());
+        List<NamedExpression> boundedSlots = inputs.stream()
+                .flatMap(input -> {
+                    Plan subPlan = ((GroupPlan) 
input).getGroup().getLogicalExpression().getPlan();

Review Comment:
   i don't think this is right, because we could write sql like that
   ```sql
   SELECT k1, COUNT(v1) FROM t1 GROUP BY k1 HAVING SUM(v2) > 10;
   ```
   the right way to bind having is write another rule that split is predicates 
into three parts
   1. AggregateFunctions **DO NOT** appear in child aggregate node
   2. AggregateFunctions **DO** appear in child aggregate node
   3. other expression
   
   And then, 
   1. push down the **first part** AggregateFunctions to aggregate node
   2. replace **both first part and second part** AggregateFunctions by 
SlotReferences generated from aggregate node's output expression
   3. if the first part is not empty, we need add a project node **on the top** 
of the filter node transformed from Having
   



-- 
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-unsubscr...@doris.apache.org

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


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

Reply via email to