paoValle opened a new pull request, #26922: URL: https://github.com/apache/datafusion/pull/26922
## Which issue does this PR close? - Closes #26462. ## Rationale for this change `SELECT lower(e.email) AS email FROM employees e ORDER BY e.email` fails to plan today, while Postgres plans it and sorts on `e.email`. The sort key is not in the select list, so it is carried into the projection to sort on it, next to the alias `email`. A `DFSchema` refuses a qualified and an unqualified field with the same name, even though the carried column is internal and projected away above the sort. ## What changes are included in this PR? `add_missing_columns` carries such a column under its flat name as an unqualified field (`e.email`, which a schema can hold next to `email`) instead of under its own name, and `sort_with_limit` rebinds the sorts to it. Nothing is renamed when the projection does not already output the name, so plans that work today are unchanged. ## What is the testing strategy for this PR? Two cases at the end of `order.slt` pin the two references apart: `ORDER BY e.email` sorts on the input column (`b@x`, then `a@y`) and `ORDER BY email` on the output one (`a@y`, then `b@x`), which is what Postgres returns for both. Two unit tests in `builder.rs` cover the plan shape: the colliding case, which fails on `main` with the ambiguous-schema error, and the case where the same name comes from two relations and nothing has to be renamed. ## Are there any user-facing changes? No new syntax or API; a query that failed to plan now plans. AI assistance: the change and the tests were drafted with an AI assistant, and the runs quoted below are from this branch. -- 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]
