@@ -252,26 +252,30 @@ impl ExecutionPlan for SortPreservingMergeExec {
252
252
MemoryConsumer :: new ( format ! ( "SortPreservingMergeExec[{partition}]" ) )
253
253
. register ( & context. runtime_env ( ) . memory_pool ) ;
254
254
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 (
256
259
& self . expr ,
257
260
& self . schema ( ) ,
258
261
& 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}\n falling back to full sort-merge" ) ;
266
+ ( 0 ..input_partitions) . map ( |i| vec ! [ i] ) . collect ( )
267
+ }
268
+ } ;
260
269
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
267
272
. into_iter ( )
268
273
. map ( |chain| {
269
274
let streams = chain
270
275
. into_iter ( )
271
276
. map ( |i| self . input . execute ( i, Arc :: clone ( & context) ) )
272
277
. collect :: < Result < Vec < _ > > > ( ) ?;
273
278
274
- // Concatenate the chain into a single stream
275
279
Ok ( Box :: pin ( RecordBatchStreamAdapter :: new (
276
280
self . input . schema ( ) ,
277
281
futures:: stream:: iter ( streams) . flatten ( ) ,
0 commit comments