anishmehta24 opened a new issue, #40461:
URL: https://github.com/apache/beam/issues/40461

   ### What happened?
   
   `SortAndBatchElements` never fills a batch up to `max_batch_weight`. A batch 
is cut as soon as adding the next element would make it equal to the limit, so 
batches always stay below it. `BatchElements` lets a batch reach its limit.
   
   ```python
   import apache_beam as beam
   from apache_beam.transforms.util import SortAndBatchElements
   
   with beam.Pipeline() as p:
     (p
      | beam.Create(['aaaaa', 'bbbbb', 'ccccc', 'ddddd'], reshuffle=False)
      | SortAndBatchElements(
          min_batch_size=1, max_batch_size=10, max_batch_weight=10)
      | beam.Map(print))
   ```
   
   Actual: four batches of one element.
   Expected: `['aaaaa', 'bbbbb']` and `['ccccc', 'ddddd']`, since each batch 
weighs 10.
   
   With `element_size_fn=lambda x: 1` and `max_batch_weight=N` this means at 
most N-1 elements per batch.
   
   Both `_SortAndBatchElementsDoFn` and `_WindowAwareSortAndBatchElementsDoFn` 
check `batch_weight + element_size >= self._max_batch_weight`; it should be `>`.
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   


-- 
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