sgrebnov opened a new pull request, #21744:
URL: https://github.com/apache/datafusion/pull/21744

   ## Which issue does this PR close?
   
   When `PushdownSort` removes a `SortExec` because a source returns `Exact` 
(guaranteeing ordering), any `fetch` (LIMIT) on the `SortExec` is silently 
dropped if the underlying plan does not support `with_fetch()`.
   
   For example, `ProjectionExec` supports `try_pushdown_sort` (delegating to 
its child) but does not implement `with_fetch()`. A plan like 
`SortExec(fetch=10) → ProjectionExec → source` that gets sort-eliminated loses 
the limit.
   
   ## What changes are included in this PR?
   
   In the `Exact` branch of `PushdownSort`, when the eliminated `SortExec` 
carried a `fetch`:
   
   1. Try `with_fetch()` on the pushed-down source first
   2. If `with_fetch()` returns `None`, fall back to wrapping with 
`GlobalLimitExec`
   
   ## Are these changes tested?
   
   Yes. Three new unit tests:
   
   - `test_sort_pushdown_exact_no_fetch_no_limit` — Exact elimination without 
fetch: no limit wrapper added
   - `test_sort_pushdown_exact_preserves_fetch_with_global_limit` — Exact 
elimination with fetch, source does NOT support `with_fetch()`: 
`GlobalLimitExec` wrapper added
   - `test_sort_pushdown_exact_preserves_fetch_with_source_support` — Exact 
elimination with fetch, source supports `with_fetch()`: limit pushed into 
source directly
   
   ## Are there any user-facing changes?
   
   No.
   


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