adriangb opened a new pull request, #19412:
URL: https://github.com/apache/datafusion/pull/19412
## Which issue does this PR close?
Closes #19410
## Rationale for this change
This PR fixes a regression introduced in #18831 where queries using GROUP BY
with ORDER BY positional reference to an aliased aggregate fail with:
```
Error during planning: Column in ORDER BY must be in GROUP BY or an
aggregate function
```
**Failing query (now fixed):**
```sql
with t as (select 'foo' as x)
select x, count(*) as "Count"
from t
group by x
order by 2 desc;
```
## What changes are included in this PR?
**Root cause:** When building the list of valid columns for ORDER BY
validation in `select.rs`, alias names were converted to `Column` using
`.into()`, which calls `from_qualified_name()` and normalizes identifiers to
lowercase. However, ORDER BY positional references resolve to columns using
schema field names, which preserve case. This caused a mismatch (e.g.,
`Column("Count")` vs `Column("count")`).
**Fix:** Use `Column::new_unqualified()` instead of `.into()` to preserve
the exact case of alias names, matching how the schema stores field names.
## Are these changes tested?
Yes, added a regression test to `order.slt`.
## Are there any user-facing changes?
No, this is a bug fix that restores expected behavior.
🤖 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]