sgrebnov commented on code in PR #21744:
URL: https://github.com/apache/datafusion/pull/21744#discussion_r3129017418
##########
datafusion/physical-optimizer/src/pushdown_sort.rs:
##########
@@ -105,7 +106,9 @@ impl PhysicalOptimizerRule for PushdownSort {
match sort_input.try_pushdown_sort(required_ordering)? {
SortOrderPushdownResult::Exact { inner } => {
let inner = if let Some(fetch) = sort_child.fetch() {
- inner.with_fetch(Some(fetch)).unwrap_or(inner)
+ inner.with_fetch(Some(fetch)).unwrap_or_else(|| {
+ Arc::new(GlobalLimitExec::new(inner, 0,
Some(fetch)))
Review Comment:
@martin-g - great point, thank you. Updated to use `LocalLimitExec`. This is
consistent with how `enforce_sorting` handles this.
https://github.com/apache/datafusion/blob/main/datafusion/physical-optimizer/src/enforce_sorting/mod.rs#L585-L594
```
// If the sort has a fetch, we need to add a limit:
if properties.output_partitioning().partition_count() == 1 {
let mut global_limit =
GlobalLimitExec::new(Arc::clone(sort_input), 0,
Some(fetch));
global_limit.set_required_ordering(required_ordering);
Arc::new(global_limit)
} else {
let mut local_limit =
LocalLimitExec::new(Arc::clone(sort_input), fetch);
local_limit.set_required_ordering(required_ordering);
Arc::new(local_limit)
}
```
Note: I didn't add set_required_ordering here because the Exact result means
the source's plan properties already guarantee the ordering, but happy to add
it for consistency / if required - please let me know.
--
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]