Skip to content

Let SortAndBatchElements batches reach max_batch_weight - #40462

Merged
shunping merged 1 commit into
apache:masterfrom
anishmehta24:fix/sort-and-batch-max-weight
Oct 8, 2026
Merged

shunping merged 1 commit into
apache:masterfrom
anishmehta24:fix/sort-and-batch-max-weight

Conversation

@anishmehta24

Copy link
Copy Markdown
Contributor

SortAndBatchElements cut a batch when adding the next element would make it weigh exactly max_batch_weight, so batches never reached the limit. Four size-5 elements with max_batch_weight=10 came out as four batches of one instead of two batches of two.

Both DoFns now use > for the weight check, same as BatchElements. Added a test for each DoFn that fails on master; util_test.py passes.

fixes #40461

Written with help from Claude.


  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

A batch was cut when adding the next element would make it equal to max_batch_weight, so it never reached the limit. Use > like BatchElements.

fixes apache#40461
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.56%. Comparing base (69bdf5f) to head (b16d34b).
⚠️ Report is 44 commits behind head on master.

Additional details and impacted files
@@              Coverage Diff              @@
##             master   #40462       +/-   ##
=============================================
+ Coverage     59.04%   79.56%   +20.51%     
=============================================
  Files          2797      487     -2310     
  Lines        280750    82225   -198525     
  Branches      12488        0    -12488     
=============================================
- Hits         165764    65420   -100344     
+ Misses       108540    16805    -91735     
+ Partials       6446        0     -6446     
Flag Coverage Δ
go ?
java ?
python 79.56% <ø> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @shunping for label python.

This pull request likely touches a core component ("core" label). Please review with scrutiny.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@shunping shunping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Thanks for fixing this.

@shunping
shunping merged commit c5d866c into apache:master Oct 8, 2026
96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SortAndBatchElements batches never reach max_batch_weight

2 participants