github-actions[bot] commented on code in PR #67152:
URL: https://github.com/apache/doris/pull/67152#discussion_r3877275427
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/FillUpQualifyMissingSlot.java:
##########
@@ -221,6 +463,35 @@ public Expression visitWindow(WindowExpression window,
List<NamedExpression> con
return planGenerator.apply(newConjuncts, projects);
}
+ /**
+ * Reject QUALIFY references to aggregate output aliases whose producer
only depends on
+ * outer correlated slots. Such an alias cannot be produced by the
aggregate (its child has
+ * no producer for the outer column), and after
NormalizeAggregate/aggregate elimination the
+ * outer slot would be left dangling in an output project. This shape
(e.g. `SELECT o.flag
+ * AS f ... GROUP BY ... QUALIFY f = ...` inside a correlated subquery) is
not supported;
+ * reject it explicitly instead of failing with a cryptic slot-validation
error.
+ */
+ private static Set<Expression>
resolveCorrelatedAggregateOutputAlias(Set<Expression> conjuncts,
+ List<NamedExpression> aggregateOutput, Optional<Scope> outerScope)
{
+ if (!outerScope.isPresent()) {
+ return conjuncts;
+ }
+ Set<Slot> correlatedSlots = outerScope.get().getCorrelatedSlots();
+ for (NamedExpression output : aggregateOutput) {
+ if (output instanceof Alias) {
Review Comment:
[P1] Handle raw correlated slots in aggregate output
This helper only inspects `Alias` outputs, but with `ONLY_FULL_GROUP_BY`
enabled an unaliased select item such as `o.flag` remains a raw
`SlotReference`. In a grouped correlated subquery that selects `i.k, o.flag,
row_number() ... AS rn` and uses `QUALIFY o.flag = 1 AND rn = 1`, the raw outer
slot is skipped here; `Resolver.lookUp` then self-matches it as an aggregate
output before its outer-scope branch can run. `NormalizeAggregate` consequently
reports a false GROUP BY error before subquery unnesting can place the outer
ExprId at the Apply-owned level. Please classify direct correlated slot outputs
too (either carry them at the Apply-owned level or reject them with the
targeted unsupported-shape error) and add a full-pipeline grouped regression
selecting the outer slot without `AS`.
--
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]