saadtajwar opened a new pull request, #24191:
URL: https://github.com/apache/datafusion/pull/24191
## Which issue does this PR close?
- Closes #21594
## Rationale for this change
The WindowTopN physical optimizer rule currently runs after
EnsureRequirements, which means it must pattern-match through SortExec nodes
that EnsureRequirements inserts:
```
FilterExec(rn <= K)
[optional ProjectionExec]
BoundedWindowAggExec(ROW_NUMBER PARTITION BY ... ORDER BY ...)
SortExec(partition_keys, order_keys) ← inserted by EnforceSorting
```
By moving WindowTopN to run before EnsureRequirements, we can simplify the
logic to avoid pattern-matching through `SortExec` node and instead use the
`ORDER BY` and `PARTITION BY` on the `BoundedWindowAggExec`
## What changes are included in this PR?
Moved `WindowTopN` to run before `EnsureRequirements`, and updated it's
logic to not expect a `SortExec` and instead use the `ORDER BY` and `PARTITION
BY` on the `BoundedWindowAggExec`
## Are these changes tested?
Yes
## Are there any user-facing changes?
These are just optimizer changes (order of optimizations and internal logic
of `WindowTopN`
--
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]