shihchengwei-lab commented on PR #27772: URL: https://github.com/apache/datafusion/pull/27772#issuecomment-7207338390
I reproduced an `ORDER BY` failure on `46cb924` when a custom optimizer pipeline runs `WindowTopN` immediately after `OutputRequirements` removes the output ordering marker. The query succeeds but returns `pk` as `NULL, 1, 2`. It should return `1, 2, NULL`. To reproduce, keep the data, SQL, and expected rows in the [regression test in this PR](https://github.com/apache/datafusion/blob/46cb924bd84a711695abfad352fa98016fd2c8d2/datafusion/core/tests/physical_optimizer/window_topn.rs#L1337) and change where the helper inserts `WindowTopN`. ```diff - let enforcement = position(&rules, EnsureRequirements::new().name()); - rules.insert(enforcement + 1, window_topn); + let removal = rules + .iter() + .rposition(|rule| rule.name() == "OutputRequirements") + .unwrap(); + rules.insert(removal + 1, window_topn); ``` ```sh cargo test -p datafusion window_topn_after_enforcement_keeps_order_relied_on ``` I ran the same SQL in a standalone harness. The PR returned the expected order at the original rule position. At the later position, both the base and the PR head returned `NULL` first. The plan had no sort above `PartitionedTopKExec` to restore `NULLS LAST`. Could we extend this fix and its regression test to cover that later rule position? AI assisted with source review, test design, and drafting. -- 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]
