-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: split BatchPartitioner::try_new into hash and round-robin constructors #19668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
483767d
refactor(repartition): split BatchPartitioner::try_new into hash and …
4f31ece
chore: run rustfmt
b96b849
docs(repartition): clarify parameters and rename non-fallible constru…
aeecd3d
docs(repartition): add documentation for try_new constructor
849e6ae
fix(clippy): remove empty line after doc comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -437,30 +437,58 @@ impl BatchPartitioner { | |
| /// Create a new [`BatchPartitioner`] with the provided [`Partitioning`] | ||
| /// | ||
| /// The time spent repartitioning will be recorded to `timer` | ||
| /// Create a new [`BatchPartitioner`] for hash partitioning | ||
| pub fn try_new_hash( | ||
| exprs: Vec<Arc<dyn PhysicalExpr>>, | ||
| num_partitions: usize, | ||
| timer: metrics::Time, | ||
| ) -> Result<Self> { | ||
| Ok(Self { | ||
| state: BatchPartitionerState::Hash { | ||
| exprs, | ||
| num_partitions, | ||
| hash_buffer: vec![], | ||
| }, | ||
| timer, | ||
| }) | ||
| } | ||
|
|
||
| /// Create a new [`BatchPartitioner`] for round-robin partitioning | ||
|
mohit7705 marked this conversation as resolved.
Outdated
mohit7705 marked this conversation as resolved.
Outdated
|
||
| pub fn try_new_round_robin( | ||
| num_partitions: usize, | ||
| timer: metrics::Time, | ||
| input_partition: usize, | ||
| num_input_partitions: usize, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ) -> Result<Self> { | ||
| Ok(Self { | ||
| state: BatchPartitionerState::RoundRobin { | ||
| num_partitions, | ||
| next_idx: (input_partition * num_partitions) / num_input_partitions, | ||
| }, | ||
| timer, | ||
| }) | ||
| } | ||
|
|
||
|
milenkovicm marked this conversation as resolved.
Outdated
|
||
| pub fn try_new( | ||
| partitioning: Partitioning, | ||
| timer: metrics::Time, | ||
| input_partition: usize, | ||
| num_input_partitions: usize, | ||
| ) -> Result<Self> { | ||
| let state = match partitioning { | ||
| Partitioning::RoundRobinBatch(num_partitions) => { | ||
| BatchPartitionerState::RoundRobin { | ||
| num_partitions, | ||
| // Distribute starting index evenly based on input partition, number of input partitions and number of partitions | ||
| // to avoid they all start at partition 0 and heavily skew on the lower partitions | ||
| next_idx: ((input_partition * num_partitions) / num_input_partitions), | ||
| } | ||
| match partitioning { | ||
| Partitioning::Hash(exprs, num_partitions) => { | ||
| Self::try_new_hash(exprs, num_partitions, timer) | ||
| } | ||
| Partitioning::Hash(exprs, num_partitions) => BatchPartitionerState::Hash { | ||
| exprs, | ||
| Partitioning::RoundRobinBatch(num_partitions) => Self::try_new_round_robin( | ||
| num_partitions, | ||
| hash_buffer: vec![], | ||
| }, | ||
| other => return not_impl_err!("Unsupported repartitioning scheme {other:?}"), | ||
| }; | ||
|
|
||
| Ok(Self { state, timer }) | ||
| timer, | ||
| input_partition, | ||
| num_input_partitions, | ||
| ), | ||
| other => { | ||
| not_impl_err!("Unsupported repartitioning scheme {other:?}") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Partition the provided [`RecordBatch`] into one or more partitioned [`RecordBatch`] | ||
|
|
@@ -1245,12 +1273,24 @@ impl RepartitionExec { | |
| input_partition: usize, | ||
| num_input_partitions: usize, | ||
| ) -> Result<()> { | ||
| let mut partitioner = BatchPartitioner::try_new( | ||
| partitioning, | ||
| metrics.repartition_time.clone(), | ||
| input_partition, | ||
| num_input_partitions, | ||
| )?; | ||
| let mut partitioner = match &partitioning { | ||
| Partitioning::Hash(exprs, num_partitions) => BatchPartitioner::try_new_hash( | ||
| exprs.clone(), | ||
| *num_partitions, | ||
| metrics.repartition_time.clone(), | ||
| )?, | ||
| Partitioning::RoundRobinBatch(num_partitions) => { | ||
| BatchPartitioner::try_new_round_robin( | ||
| *num_partitions, | ||
| metrics.repartition_time.clone(), | ||
| input_partition, | ||
| num_input_partitions, | ||
| )? | ||
| } | ||
| other => { | ||
| return not_impl_err!("Unsupported repartitioning scheme {other:?}"); | ||
| } | ||
| }; | ||
|
|
||
| // While there are still outputs to send to, keep pulling inputs | ||
| let mut batches_until_yield = partitioner.num_partitions(); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.