raams95 opened a new pull request, #40549:
URL: https://github.com/apache/beam/pull/40549

   Fixes #21316
   
   `ConcatRangeTracker._compute_cumulative_weights` fills in missing bundle 
weights with the average of the known weights. A weight of 0 is already treated 
as missing (`s.weight or avg`), but zeros were still counted when computing the 
average. If every bundle has weight 0, the average is 0, the total is 0, and 
this line raises `ZeroDivisionError: float division by zero`:
   
   ```python
   running_total.append(max(min_diff, min(1, running_total[-1] + w / total)))
   ```
   
   This happens when a source's `split()` returns bundles with weight 0, for 
example when the weights are sizes rounded down to whole MB for bundles smaller 
than 1 MB, which was the case in the issue. #12142 fixed the MongoDB source on 
its own, but `ConcatSource` still fails for any source that does this.
   
   This change leaves zero weights out of the average, in the same way as 
`None` weights. When every weight is 0 or missing, the tracker falls back to 
equal weights of 1.0, which it already does when no weights are given.
   
   I added `test_zero_weight_bundles` to `concat_source_test.py`. It raises 
`ZeroDivisionError` before the change and passes after it.
   
   Testing:
   - `pytest apache_beam/io/concat_source_test.py apache_beam/io/iobase_test.py 
apache_beam/io/filebasedsource_test.py apache_beam/io/textio_test.py`
   - `yapf --diff` and `ruff check` on the changed files
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us 
incorporate your contribution quickly and easily:
   
    - [x] Mention the appropriate issue in your description (for example: 
`addresses #123` or `fixes #456`).
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual 
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more 
tips on [how to make review process 
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to