jayzhan211 commented on PR #27772:
URL: https://github.com/apache/datafusion/pull/27772#issuecomment-7218016041

   > Could we extend this fix and its regression test to cover that later rule 
position?
   
   Thanks for the repro. I'd like to keep this PR to positions before 
`OutputRequirements` removes its marker, and fix the later positions in a 
separate PR that keeps the marker until the physical planner's final check, 
with your case as its test. Does that work for you?
   
   Your case reproduces on this branch: with `WindowTopN` just before the 
removal, the window is kept and `pk` comes back `1, 2, NULL`; just after it, 
`NULL, 1, 2`. Once `EnsureRequirements` drops the sort for `ORDER BY pk`, the 
marker is the only node that declares that order, and the removal drops it 
([output_requirements.rs](https://github.com/apache/datafusion/blob/46cb924bd84a711695abfad352fa98016fd2c8d2/datafusion/physical-optimizer/src/output_requirements.rs#L349-L351)).
 From then on, neither this PR's check nor the planner's final check can see 
that the query relies on the window's order. Any rule that changes the output 
order after that point has the same blind spot, so keeping the marker fixes 
them together. A check in `WindowTopN` alone would have to treat every change 
to the output order as a break, which would also block the rewrite for queries 
without `ORDER BY`.
   


-- 
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]

Reply via email to