galaxytemple opened a new pull request, #27646: URL: https://github.com/apache/datafusion/pull/27646
## Which issue does this PR close? - Closes #27418 ## Rationale for this change When a projection outputs the same volatile expression more than once (e.g. `SELECT floor(random() * 3) AS x, floor(random() * 3) AS y`), `EquivalenceGroup::project` groups both targets under the same source expression key and places `x` and `y` in the same equivalence class (`x = y`). And this false `x = y` equivalence causes downstream `ORDER BY x, y` (including across `UNION ALL` after #27347) to drop `y` from `SortExec` and return rows unsorted on `y`. ## What changes are included in this PR? - Skip volatile source expressions (`is_volatile(source)`) at the start of the `mapping.iter()` loop in `EquivalenceGroup::project` so they do not form equivalence classes across projected targets. - Add a unit test in `class.rs` and a sqllogictest in `union.slt`. ## What is the testing strategy for this PR? Unit test (`class.rs`): - Projects a `Volatility::Volatile` UDF expression `f(a)` to two target columns (`x` and `y`) via `ProjectionMapping` and asserts that `EquivalenceGroup::project` returns an empty group (`projected.is_empty()`) instead of `x=y`. Sqllogictest (`union.slt`): - Runs `ORDER BY x, y` on a `UNION ALL` query projecting `floor(random() * 3) AS x, floor(random() * 3) AS y` and checks the physical plan to verify that `x` and `y` are not treated as equivalent (both remain in `SortExec`). ## Are there any user-facing changes? No API changes. Bug fix only. -- 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]
