comphead commented on code in PR #19775:
URL: https://github.com/apache/datafusion/pull/19775#discussion_r2691315565


##########
datafusion/physical-plan/src/repartition/mod.rs:
##########
@@ -591,33 +592,46 @@ impl BatchPartitioner {
 
                     // Borrowing partitioner timer to prevent moving `self` to 
closure
                     let partitioner_timer = &self.timer;
-                    let it = indices
-                        .into_iter()
-                        .enumerate()
-                        .filter_map(|(partition, indices)| {
-                            let indices: PrimitiveArray<UInt32Type> = 
indices.into();
-                            (!indices.is_empty()).then_some((partition, 
indices))
-                        })
-                        .map(move |(partition, indices)| {
+
+                    let mut partitioned_batches = vec![];
+                    for (partition, p_indices) in 
indices.iter_mut().enumerate() {
+                        if !p_indices.is_empty() {
+                            let taken_indices = std::mem::take(p_indices);
+                            let indices_array: PrimitiveArray<UInt32Type> =
+                                taken_indices.into();
+
                             // Tracking time required for repartitioned 
batches construction
                             let _timer = partitioner_timer.timer();
 
                             // Produce batches based on indices
-                            let columns = take_arrays(batch.columns(), 
&indices, None)?;
+                            let columns =
+                                take_arrays(batch.columns(), &indices_array, 
None)?;
 
                             let mut options = RecordBatchOptions::new();
-                            options = 
options.with_row_count(Some(indices.len()));
+                            options = 
options.with_row_count(Some(indices_array.len()));
                             let batch = RecordBatch::try_new_with_options(
                                 batch.schema(),
                                 columns,
                                 &options,
                             )
                             .unwrap();
 
-                            Ok((partition, batch))
-                        });
+                            partitioned_batches.push(Ok((partition, batch)));
+
+                            // Return the taken vec
+                            let (_, buffer, _) = indices_array.into_parts();
+                            let mut vec =
+                                
buffer.into_inner().into_vec::<u32>().map_err(|e| {
+                                    DataFusionError::Internal(format!(

Review Comment:
   ```suggestion
                                       internal_datafusion_err!(
   ```



-- 
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]

Reply via email to