rohdesamuel commented on code in PR #27280:
URL: https://github.com/apache/beam/pull/27280#discussion_r1245577985
##########
sdks/python/apache_beam/runners/worker/data_sampler.py:
##########
@@ -115,19 +130,47 @@ def remove_windowed_value(self, el: Union[WindowedValue,
Any]) -> Any:
el = el.value
return el
- def flush(self, clear: bool = True) -> List[bytes]:
+ def flush(self, clear: bool = True) -> List[beam_fn_api_pb2.SampledElement]:
"""Returns all samples and optionally clears buffer if clear is True."""
with self._samples_lock:
+ # TODO(rohdesamuel): There can duplicates between the exceptions and
+ # samples. This happens when the OutputSampler samples during an
+ # exception. The fix is to create a OutputSampler per process bundle.
+ # Until then use a set to keep track of the elements.
+ seen = set(el for el, _ in self._exceptions)
if isinstance(self._coder_impl, WindowedValueCoderImpl):
- samples = [s for s in self._samples]
+ exceptions = [s for s in self._exceptions]
+ samples = [s for s in self._samples if s not in seen]
else:
- samples = [self.remove_windowed_value(s) for s in self._samples]
+ exceptions = [
+ (self.remove_windowed_value(a), b) for a, b in self._exceptions
+ ]
+ samples = [
+ self.remove_windowed_value(s) for s in self._samples
+ if s not in seen
+ ]
# Encode in the nested context b/c this ensures that the SDK can decode
# the bytes with the ToStringFn.
if clear:
self._samples.clear()
Review Comment:
TODO: clear _exceptions
--
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]