goldmedal commented on code in PR #15423:
URL: https://github.com/apache/datafusion/pull/15423#discussion_r2051721176


##########
datafusion/physical-plan/src/repartition/mod.rs:
##########
@@ -320,6 +336,68 @@ impl BatchPartitioner {
                             Ok((partition, batch))
                         });
 
+                    Box::new(it)
+                }
+                BatchPartitionerState::HashSelectionVector {
+                    random_state,
+                    exprs,
+                    num_partitions,
+                } => {
+                    let mut hash_buffer = vec![];
+                    let timer = self.timer.timer();
+                    let arrays = exprs
+                        .iter()
+                        .map(|expr| 
expr.evaluate(&batch)?.into_array(batch.num_rows()))
+                        .collect::<Result<Vec<_>>>()?;
+
+                    hash_buffer.resize(batch.num_rows(), 0);
+                    create_hashes(&arrays, random_state, &mut hash_buffer)?;
+
+                    let hash_vector = UInt64Array::from(hash_buffer)
+                        .unary_mut(|a| a % *num_partitions as u64)
+                        .unwrap();
+
+                    let mut fields = batch
+                        .schema()
+                        .fields()
+                        .iter()
+                        .map(Arc::clone)
+                        .collect::<Vec<_>>();
+                    fields.push(Arc::new(Field::new(
+                        SELECTION_FIELD_NAME,
+                        DataType::Boolean,
+                        false,
+                    )));
+                    let schema = 
Arc::new(arrow::datatypes::Schema::new(fields));
+                    // Finished building index-arrays for output partitions
+                    timer.done();
+
+                    // Borrowing partitioner timer to prevent moving `self` to 
closure
+                    let partitioner_timer = &self.timer;
+
+                    let it = (0..*num_partitions).map(move |partition| {
+                        // Tracking time required for repartitioned batches 
construction
+                        let _timer = partitioner_timer.timer();
+                        let selection_array = arrow_ord::cmp::eq(
+                            &hash_vector,
+                            &UInt64Array::from(vec![partition as u64; 
batch.num_rows()]),
+                        )
+                        .unwrap();
+                        let selection_vector = Arc::new(selection_array);

Review Comment:
   Is there a more efficient way to do it? 🤔  In the profile result, it spends 
many CPU time here.
   ![Screenshot 2025-04-20 at 9 08 36 
PM](https://github.com/user-attachments/assets/7b0018a2-c4c0-4285-b8b3-ab52f18ff8b8)
   



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to