adriangb opened a new pull request, #27737:
URL: https://github.com/apache/datafusion/pull/27737
## Which issue does this PR close?
- No issue filed. The bug and fix are small and described below.
## Rationale for this change
This query fails with "Correlated scalar subquery must be aggregated to
return at most one row". The same query with `NOT MATERIALIZED` returns the
correct rows.
```sql
SELECT column1, (WITH c AS MATERIALIZED (SELECT column1 x, column2 y FROM t)
SELECT max(y) FROM c WHERE c.x = t.column1) FROM t;
```
## What changes are included in this PR?
`strip_inner_query` in `datafusion/expr/src/logical_plan/invariants.rs`
looks through `Projection` and `SubqueryAlias`. It now also looks through a
`MaterializedCte` node into its continuation, which holds the `Aggregate`.
Decorrelation (`scalar_subquery_to_join`) already handles the resulting plan.
## What is the testing strategy for this PR?
New cases in `cte_materialized.slt`: one with a match for every outer row,
and one where some outer rows have no match and get `NULL`.
## Are there any user-facing changes?
The query above now runs. No API changes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]