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


##########
datafusion/physical-plan/src/repartition/mod.rs:
##########
@@ -316,6 +326,71 @@ impl BatchPartitioner {
                             Ok((partition, batch))
                         });
 
+                    Box::new(it)
+                }
+                BatchPartitionerState::HashSelectVector {
+                    random_state,
+                    exprs,
+                    num_partitions,
+                    hash_buffer,
+                } => {
+                    let timer = self.timer.timer();
+                    let arrays = exprs
+                        .iter()
+                        .map(|expr| 
expr.evaluate(&batch)?.into_array(batch.num_rows()))
+                        .collect::<Result<Vec<_>>>()?;
+
+                    create_hashes(&arrays, random_state, hash_buffer)?;
+
+                    let hash_vector = hash_buffer
+                        .iter()
+                        .map(|hash| *hash % *num_partitions as u64)
+                        .collect::<Vec<_>>();
+                    let mut fields = batch
+                        .schema()
+                        .fields()
+                        .iter()
+                        .map(|f| Arc::clone(f))
+                        .collect::<Vec<_>>();
+                    fields.push(Arc::new(Field::new(
+                        "selection",
+                        DataType::Boolean,
+                        false,
+                    )));
+                    // 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).into_iter().map(move 
|partition| {
+                        // Tracking time required for repartitioned batches 
construction
+                        let _timer = partitioner_timer.timer();
+                        let select_vector = hash_vector
+                            .iter()
+                            .map(|&hash| hash == partition as u64)
+                            .collect::<Vec<_>>();
+                        let new_col: ArrayRef =
+                            Arc::new(BooleanArray::from(select_vector)) as 
ArrayRef;
+                        let mut columns = batch
+                            .columns()
+                            .iter()
+                            .map(|c| c.clone())
+                            .collect::<Vec<_>>();
+                        columns.push(new_col);
+
+                        let mut options = RecordBatchOptions::new();
+                        options = 
options.with_row_count(Some(batch.num_rows()));
+                        let batch = RecordBatch::try_new_with_options(
+                            batch.schema(),

Review Comment:
   You should probably add the column to the schema (e.g. a 
`__selection_vector` of boolean type).
   



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