Skip to content
Open
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
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/runners/worker/opcounters.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def update_from_batch(self, windowed_batch):
batch_length = self.producer_batch_converter.get_length(
windowed_batch.values)
self.element_counter.update(batch_length)
if batch_length == 0:
return

mean_element_size = self.producer_batch_converter.estimate_byte_size(
windowed_batch.values) / batch_length
Expand Down
16 changes: 16 additions & 0 deletions sdks/python/apache_beam/runners/worker/opcounters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ def test_update_batch(self):

self.verify_counters(opcounts, 200, size_per_element)

def test_update_empty_batch(self):
opcounts = OperationCounters(
CounterFactory(),
'some-name',
coders.FastPrimitivesCoder(),
0,
producer_batch_converter=typehints.batch.BatchConverter.from_typehints(
element_type=typehints.Any,
batch_type=typehints.List[typehints.Any]))

self.verify_counters(opcounts, 0, math.nan)

opcounts.update_from_batch(GlobalWindows.windowed_batch([]))

self.verify_counters(opcounts, 0, math.nan)

def test_should_sample(self):
# Order of magnitude more buckets than highest constant in code under test.
buckets = [0] * 300
Expand Down
Loading