Dandandan opened a new pull request, #24783: URL: https://github.com/apache/datafusion/pull/24783
## Which issue does this PR close? - Closes #. ## Rationale for this change A correlated scalar subquery must return at most one row per set of outer values. `check_aggregation_in_scalar_subquery` required an aggregate expression to establish that, so this query fails to plan: ```sql select o.id, (select k from dim where dim.k = o.k group by k) from o ``` with `Correlated scalar subquery must be aggregated to return at most one row`. The aggregate expression is not what makes the subquery scalar. The grouping is. An empty `GROUP BY` returns one row, and a `GROUP BY` on only correlated columns returns at most one group per set of outer values. The function already checks the second condition, so the aggregate check is redundant and rejects valid queries. ## What changes are included in this PR? Removes the `aggr_expr.is_empty()` check. The `GROUP BY` check below it is unchanged, so a `GROUP BY` on a non-correlated column is still rejected. These subqueries decorrelate to a plain `LEFT JOIN` like any other, so no changes are needed outside the check: ``` Projection: fact.id, __scalar_sq_1.k AS g --Left Join: fact.k = __scalar_sq_1.k ----TableScan: fact projection=[id, k] ----SubqueryAlias: __scalar_sq_1 ------Aggregate: groupBy=[[dim.k]], aggr=[[]] --------TableScan: dim projection=[k] ``` ## Are these changes tested? Yes. An existing case in `subquery.slt` asserted the old error; it now checks the results and the plan. The negative case for a `GROUP BY` on a non-correlated column is unchanged and still passes. ## Are there any user-facing changes? Correlated scalar subqueries that group by only correlated columns and have no aggregate expression now plan instead of returning an error. No existing plan changes. -- 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]
