mihailotim-db opened a new pull request, #58123:
URL: https://github.com/apache/spark/pull/58123
### What changes were proposed in this pull request?
This PR fixes a regression introduced by SPARK-58171 when resolving a
correlated scalar subquery whose `HAVING`
clause references an outer grouping expression.
It:
- Aliases an outer grouping expression when adding it to an `Aggregate`
output.
- Aligns auto-generated `OuterReference` alias names between the
fixed-point analyzer and single-pass resolver.
- Adds an end-to-end SQL regression test.
### Why are the changes needed?
An outer grouping expression could be added directly to the aggregate
output without a fresh expression ID. A
later analyzer iteration could alias it, leaving the parent `Filter` bound
to the leaked outer expression ID
and causing analysis to fail with
`MISSING_ATTRIBUTES.RESOLVED_ATTRIBUTE_APPEAR_IN_OPERATION`.
### Does this PR introduce _any_ user-facing change?
Yes. This fixes a regression on master.
Previously, a query such as:
```sql
SELECT (
SELECT COUNT(inner_value)
FROM VALUES (1), (2) AS inner_table(inner_value)
GROUP BY outer_table.outer_key
HAVING outer_table.outer_key = outer_table.outer_key
)
FROM VALUES (DATE '2024-01-01'), (DATE '2024-01-02')
AS outer_table(outer_key)
could fail during analysis. It now resolves successfully and returns two
rows containing 2.
### How was this patch tested?
Added an end-to-end test to SubquerySuite that executes the affected SQL
query and verifies that it returns
Seq(Row(2L), Row(2L)).
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-5)
--
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]