Skip to content
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

Improve round-robin repartitioning #6047

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions datafusion/core/src/physical_plan/repartition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@ impl BatchPartitioner {
/// Create a new [`BatchPartitioner`] with the provided [`Partitioning`]
///
/// The time spent repartitioning will be recorded to `timer`
pub fn try_new(partitioning: Partitioning, timer: metrics::Time) -> Result<Self> {
pub fn try_new(
partitioning: Partitioning,
partition: usize,
num_input_partitions: usize,
timer: metrics::Time,
) -> Result<Self> {
let state = match partitioning {
Partitioning::RoundRobinBatch(num_partitions) => {
BatchPartitionerState::RoundRobin {
num_partitions,
next_idx: 0,
next_idx: (num_partitions / num_input_partitions) * partition,
}
}
Partitioning::Hash(exprs, num_partitions) => BatchPartitionerState::Hash {
Expand Down Expand Up @@ -492,8 +497,12 @@ impl RepartitionExec {
r_metrics: RepartitionMetrics,
context: Arc<TaskContext>,
) -> Result<()> {
let mut partitioner =
BatchPartitioner::try_new(partitioning, r_metrics.repart_time.clone())?;
let mut partitioner = BatchPartitioner::try_new(
partitioning,
i,
input.output_partitioning().partition_count(),
r_metrics.repart_time.clone(),
)?;

// execute the child operator
let timer = r_metrics.fetch_time.timer();
Expand Down
3 changes: 2 additions & 1 deletion datafusion/core/src/scheduler/pipeline/repartition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ impl RepartitionPipeline {
assert_ne!(output_count, 0);

// TODO: metrics support
let partitioner = BatchPartitioner::try_new(output, Default::default())?;
let partitioner =
BatchPartitioner::try_new(output, 0, output_count, Default::default())?;

let state = Mutex::new(RepartitionState {
partitioner,
Expand Down