@@ -23,6 +23,7 @@ use crate::execution::shuffle::{CometPartitioning, CompressionCodec, ShuffleBloc
2323use crate :: execution:: tracing:: { with_trace, with_trace_async} ;
2424use arrow:: compute:: interleave_record_batch;
2525use async_trait:: async_trait;
26+ use datafusion:: common:: exec_datafusion_err;
2627use datafusion:: common:: utils:: proxy:: VecAllocExt ;
2728use datafusion:: physical_expr:: { EquivalenceProperties , Partitioning } ;
2829use datafusion:: physical_plan:: execution_plan:: { Boundedness , EmissionType } ;
@@ -45,7 +46,6 @@ use datafusion::{
4546use datafusion_comet_spark_expr:: hash_funcs:: murmur3:: create_murmur3_hashes;
4647use futures:: { StreamExt , TryFutureExt , TryStreamExt } ;
4748use itertools:: Itertools ;
48- use std:: io:: Error ;
4949use std:: {
5050 any:: Any ,
5151 fmt,
@@ -255,10 +255,15 @@ async fn external_shuffle(
255255 // into the corresponding partition buffer.
256256 // Otherwise, pull the next batch from the input stream might overwrite the
257257 // current batch in the repartitioner.
258- repartitioner. insert_batch ( batch?) . await ?;
258+ repartitioner
259+ . insert_batch ( batch?)
260+ . await
261+ . map_err ( |err| exec_datafusion_err ! ( "Error inserting batch: {err}" ) ) ?;
259262 }
260263
261- repartitioner. shuffle_write ( ) ?;
264+ repartitioner
265+ . shuffle_write ( )
266+ . map_err ( |err| exec_datafusion_err ! ( "Error in shuffle write: {err}" ) ) ?;
262267
263268 // shuffle writer always has empty output
264269 Ok ( Box :: pin ( EmptyRecordBatchStream :: new ( Arc :: clone ( & schema) ) ) as SendableRecordBatchStream )
@@ -803,9 +808,9 @@ impl ShufflePartitioner for MultiPartitionShuffleRepartitioner {
803808 // if we wrote a spill file for this partition then copy the
804809 // contents into the shuffle file
805810 if let Some ( spill_path) = self . partition_writers [ i] . path ( ) {
806- let mut spill_file = BufReader :: new ( File :: open ( spill_path) . map_err ( to_df_err ) ?) ;
811+ let mut spill_file = BufReader :: new ( File :: open ( spill_path) ?) ;
807812 let mut write_timer = self . metrics . write_time . timer ( ) ;
808- std:: io:: copy ( & mut spill_file, & mut output_data) . map_err ( to_df_err ) ?;
813+ std:: io:: copy ( & mut spill_file, & mut output_data) ?;
809814 write_timer. stop ( ) ;
810815 }
811816
@@ -826,17 +831,15 @@ impl ShufflePartitioner for MultiPartitionShuffleRepartitioner {
826831 write_timer. stop ( ) ;
827832
828833 // add one extra offset at last to ease partition length computation
829- offsets[ num_output_partitions] = output_data. stream_position ( ) . map_err ( to_df_err ) ?;
834+ offsets[ num_output_partitions] = output_data. stream_position ( ) ?;
830835
831836 let mut write_timer = self . metrics . write_time . timer ( ) ;
832837 let mut output_index =
833838 BufWriter :: new ( File :: create ( index_file) . map_err ( |e| {
834839 DataFusionError :: Execution ( format ! ( "shuffle write error: {e:?}" ) )
835840 } ) ?) ;
836841 for offset in offsets {
837- output_index
838- . write_all ( & ( offset as i64 ) . to_le_bytes ( ) [ ..] )
839- . map_err ( to_df_err) ?;
842+ output_index. write_all ( & ( offset as i64 ) . to_le_bytes ( ) [ ..] ) ?;
840843 }
841844 output_index. flush ( ) ?;
842845 write_timer. stop ( ) ;
@@ -893,8 +896,7 @@ impl SinglePartitionShufflePartitioner {
893896 . write ( true )
894897 . create ( true )
895898 . truncate ( true )
896- . open ( output_data_path)
897- . map_err ( to_df_err) ?;
899+ . open ( output_data_path) ?;
898900
899901 let output_data_writer =
900902 BufBatchWriter :: new ( shuffle_block_writer, output_data_file, write_buffer_size) ;
@@ -1011,9 +1013,7 @@ impl ShufflePartitioner for SinglePartitionShufflePartitioner {
10111013 let mut index_buf_writer = BufWriter :: new ( index_file) ;
10121014 let data_file_length = self . output_data_writer . writer_stream_position ( ) ?;
10131015 for offset in [ 0 , data_file_length] {
1014- index_buf_writer
1015- . write_all ( & ( offset as i64 ) . to_le_bytes ( ) [ ..] )
1016- . map_err ( to_df_err) ?;
1016+ index_buf_writer. write_all ( & ( offset as i64 ) . to_le_bytes ( ) [ ..] ) ?;
10171017 }
10181018 index_buf_writer. flush ( ) ?;
10191019
@@ -1025,10 +1025,6 @@ impl ShufflePartitioner for SinglePartitionShufflePartitioner {
10251025 }
10261026}
10271027
1028- fn to_df_err ( e : Error ) -> DataFusionError {
1029- DataFusionError :: Execution ( format ! ( "shuffle write error: {e:?}" ) )
1030- }
1031-
10321028/// A helper struct to produce shuffled batches.
10331029/// This struct takes ownership of the buffered batches and partition indices from the
10341030/// ShuffleRepartitioner, and provides an iterator over the batches in the specified partitions.
0 commit comments