Skip to content

Commit a93e81e

Browse files
committed
add order needed
1 parent 70a3c94 commit a93e81e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

datafusion/physical-optimizer/src/enforce_distribution.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,13 @@ pub fn ensure_distribution(
14071407
// It was removed by `remove_dist_changing_operators`
14081408
// and we need to add it back.
14091409
if fetch.is_some() {
1410-
// It's safe to unwrap because `spm` is set only if `fetch` is set.
1411-
let plan = spm.unwrap().with_fetch(fetch.take()).unwrap();
1410+
// We can make sure that `plan` has an ordering because
1411+
// `SortPreservingMergeExec` requires ordering to be constructed.
1412+
// If there is no ordering, `SortPreservingMergeExec::new` will panic
1413+
let ordering = plan.output_ordering().cloned().unwrap();
1414+
let plan = Arc::new(
1415+
SortPreservingMergeExec::new(ordering, plan).with_fetch(fetch.take()),
1416+
);
14121417
optimized_distribution_ctx =
14131418
DistributionContext::new(plan, data, vec![optimized_distribution_ctx]);
14141419
}

0 commit comments

Comments
 (0)