924060929 commented on code in PR #49341: URL: https://github.com/apache/doris/pull/49341#discussion_r2084332835
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java: ########## @@ -387,7 +392,40 @@ private LogicalHaving<Plan> bindHaving(MatchingContext<LogicalHaving<Plan>> ctx) Supplier<Scope> childChildrenOutput = Suppliers.memoize(() -> toScope(cascadesContext, PlanUtils.fastGetChildrenOutputs(childPlan.children())) ); - return bindHavingByScopes(having, cascadesContext, childOutput, childChildrenOutput); + LogicalHaving<Plan> boundHaving = bindHavingByScopes(having, having.child(), + cascadesContext, childOutput, childChildrenOutput); + if (!SqlModeHelper.hasOnlyFullGroupBy() && childPlan instanceof LogicalProject) { + // ATTN, process having(project) that have aggregate function in having + LogicalProject<?> project = (LogicalProject<?>) childPlan; + List<AggregateFunction> aggFuncs = CollectNonWindowedAggFuncs.collect(boundHaving.getConjuncts()); + if (!aggFuncs.isEmpty()) { + Map<Expression, Expression> replaceMap = Maps.newHashMap(); + for (AggregateFunction aggFunc : aggFuncs) { + // ATTN: this is a little trick here. since replace check replace successful with equal operator + // here, we generate a new aggFunc to replace to avoid rewrite its child. + // because we do not want to replace agg func agg(child) to agg(any_value(child)) + replaceMap.put(aggFunc, aggFunc.withChildren(aggFunc.children())); Review Comment: where is the check that use `==`, please add the comment -- 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