Skip to content

Commit b469b71

Browse files
committed
fall back to full merge on errors
1 parent c138b24 commit b469b71

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

datafusion/physical-plan/src/sorts/sort_preserving_merge.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,26 +252,30 @@ impl ExecutionPlan for SortPreservingMergeExec {
252252
MemoryConsumer::new(format!("SortPreservingMergeExec[{partition}]"))
253253
.register(&context.runtime_env().memory_pool);
254254

255-
let statistics = MinMaxStatistics::new_from_statistics(
255+
// Organize the input partitions into chains,
256+
// where elements of each chain are input partitions that are
257+
// non-overlapping, and each chain is ordered by their min/max statistics.
258+
let stream_packing = match MinMaxStatistics::new_from_statistics(
256259
&self.expr,
257260
&self.schema(),
258261
&self.input.statistics_by_partition()?,
259-
)?;
262+
) {
263+
Ok(statistics) => statistics.first_fit(),
264+
Err(e) => {
265+
log::debug!("error analyzing statistics for plan: {e}\nfalling back to full sort-merge");
266+
(0..input_partitions).map(|i| vec![i]).collect()
267+
}
268+
};
260269

261-
// Organize the input partitions into chains,
262-
// where elements of each chain are input partitions that are
263-
// non-overlapping, and each chain is ordered by their min/max statistics.
264-
// Then concatenate each chain into a single stream.
265-
let mut streams = statistics
266-
.first_fit()
270+
// Concatenate each chain into a single stream.
271+
let mut streams = stream_packing
267272
.into_iter()
268273
.map(|chain| {
269274
let streams = chain
270275
.into_iter()
271276
.map(|i| self.input.execute(i, Arc::clone(&context)))
272277
.collect::<Result<Vec<_>>>()?;
273278

274-
// Concatenate the chain into a single stream
275279
Ok(Box::pin(RecordBatchStreamAdapter::new(
276280
self.input.schema(),
277281
futures::stream::iter(streams).flatten(),

0 commit comments

Comments
 (0)