Skip to content

Conversation

@mohit7705
Copy link
Contributor

Which issue does this PR close?

Closes #19664


Rationale for this change

After #18880, BatchPartitioner::try_new gained additional parameters that are
only relevant for round-robin repartitioning. This made the constructor API
confusing, as hash repartitioning received parameters it does not use.

Splitting the constructor improves clarity and avoids passing
round-robin–specific parameters to hash partitioning.


What changes are included in this PR?

  • Introduce BatchPartitioner::try_new_hash
  • Introduce BatchPartitioner::try_new_round_robin
  • Refactor callers to use the specialized constructors
  • Retain BatchPartitioner::try_new as a delegator for backward compatibility

This is a pure refactor; behavior is unchanged.


Are these changes tested?

Yes. Existing tests cover this code path.
All builds pass locally.


Are there any user-facing changes?

No. This change is internal only and does not affect user-facing behavior or APIs.

@github-actions github-actions bot added the physical-plan Changes to the physical-plan crate label Jan 6, 2026
Copy link
Contributor

@milenkovicm milenkovicm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @mohit7705
looks good, just few comments

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW we will need to backport this into branch-52 if we want to include it in the release

@milenkovicm milenkovicm changed the title refactor(repartition): split BatchPartitioner::try_new into hash and round-robin constructors feat: split BatchPartitioner::try_new into hash and round-robin constructors Jan 6, 2026
Copy link
Contributor

@milenkovicm milenkovicm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please add documentation for try_new as well please ?

@milenkovicm
Copy link
Contributor

thanks @alamb & @mohit7705
i have just one small comment, and then we can merge this.
If @mohit7705 wants to create patch for 52 would be great otherwise i'll create it tomorrow morning

@mohit7705
Copy link
Contributor Author

Done 👍

Added documentation for try_new explaining its purpose, parameters, and error conditions.

@mohit7705 mohit7705 requested a review from milenkovicm January 6, 2026 20:34
Copy link
Contributor

@milenkovicm milenkovicm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @mohit7705

@mohit7705
Copy link
Contributor Author

Thanks again for the reviews! 🙏
@milenkovicm
All checks are green now — feel free to merge whenever convenient.

@milenkovicm milenkovicm added this pull request to the merge queue Jan 7, 2026
Merged via the queue into apache:main with commit 680ddcc Jan 7, 2026
32 checks passed
@milenkovicm
Copy link
Contributor

thanks @mohit7705
It would make sense to have this released with datafusion 52 (#18566). would you be able to provide patch to branch 52 or you want us to do it ?

num_partitions: usize,
timer: metrics::Time,
input_partition: usize,
num_input_partitions: usize,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_input_partitions == 0 would lead to a panic below (division by 0). It would be good to prevent this or at least document it as a non-supported value.

mohit7705 added a commit to mohit7705/datafusion that referenced this pull request Jan 7, 2026
…ructors (apache#19668)

### Which issue does this PR close?

Closes apache#19664

---

### Rationale for this change

After apache#18880, `BatchPartitioner::try_new` gained additional parameters
that are
only relevant for round-robin repartitioning. This made the constructor
API
confusing, as hash repartitioning received parameters it does not use.

Splitting the constructor improves clarity and avoids passing
round-robin–specific parameters to hash partitioning.

---

### What changes are included in this PR?

- Introduce `BatchPartitioner::try_new_hash`
- Introduce `BatchPartitioner::try_new_round_robin`
- Refactor callers to use the specialized constructors
- Retain `BatchPartitioner::try_new` as a delegator for backward
compatibility

This is a pure refactor; behavior is unchanged.

---

### Are these changes tested?

Yes. Existing tests cover this code path.
All builds pass locally.

---

### Are there any user-facing changes?

No. This change is internal only and does not affect user-facing
behavior or APIs.

---------

Co-authored-by: Your Name <[email protected]>
@mohit7705
Copy link
Contributor Author

Thanks @milenkovicm!

I’ve opened the backport PR to branch-52 as discussed.
Please have a look when you get a chance, and feel free to merge if everything looks good

xudong963 pushed a commit that referenced this pull request Jan 8, 2026
… constructors (#19681)

Backport of #19668 to branch-52.

This PR cherry-picks commit 680ddcc from main.

Includes:
- Split of BatchPartitioner::try_new into hash and round-robin
constructors
- Documentation improvements
- No behavior changes


part of #18566

Co-authored-by: Your Name <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split BatchPartitioner::try_new(..) into BatchPartitioner::new_hash and BatchPartitioner::new_round_robin

4 participants