zebsme commented on code in PR #15423: URL: https://github.com/apache/datafusion/pull/15423#discussion_r2019843158
########## datafusion/physical-plan/src/repartition/mod.rs: ########## @@ -316,6 +334,70 @@ impl BatchPartitioner { Ok((partition, batch)) }); + Box::new(it) + } + BatchPartitionerState::HashSelectionVector { + 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<_>>>()?; + + hash_buffer.clear(); + hash_buffer.resize(batch.num_rows(), 0); + 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(Arc::clone) + .collect::<Vec<_>>(); + fields.push(Arc::new(Field::new( + SELECTION_FILED_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_vector = Arc::new( + hash_vector + .iter() + .map(|&hash| Some(hash == partition as u64)) + .collect::<BooleanArray>(), + ); + let mut columns = + batch.columns().iter().map(Arc::clone).collect::<Vec<_>>(); Review Comment: Maybe this could be written as follows: ``` let mut columns = batch.columns().to_vec(); columns.push(selection_vector); ``` already tested in `many_to_many_hash_select_vector` -- 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