github-actions[bot] commented on code in PR #41054:
URL: https://github.com/apache/beam/pull/41054#discussion_r4643051552
##########
sdks/python/apache_beam/transforms/combiners.py:
##########
@@ -801,17 +803,98 @@ def add_input(self, accumulator, element, *args,
**kwargs):
]
+class ToSingleElementCollection(CombinerWithoutDefaults):
+ """Base class for combining a PCollection into a single element.
+
+ This is for combining a PCollection into a single element in the cases where
+ there is no value (and significant overhead) in using a combiner as the
+ output is no smaller than its input.
+ """
+ def expand(self, pcoll):
+ raise NotImplementedError
+
+ def _expand(self, pcoll, post_process):
+ if pcoll.is_bounded and pcoll.windowing.windowfn == window.GlobalWindows():
Review Comment:
**🔴 Critical**: `pcoll.windowing.windowfn == window.GlobalWindows()` matches
globally windowed PCollections that have non-default triggers (e.g.,
`Repeatedly(AfterCount(n))`) or custom `TimestampCombiner`s. In the `if` branch:
1. `DoOnce >> Create([None]) | FlatMap(..., side_input)` only executes once
instead of firing per trigger pane, and `pvalue.AsIter` fails at runtime if the
side input emits multiple panes (`ValueError: PCollection of size 2 with more
than one element accessed as a singleton view`).
2. `result._windowing = pcoll.windowing` overwrites the `DefaultTrigger` on
`result` with `pcoll`'s custom trigger without resetting it to its continuation
trigger, and ignores any custom `timestamp_combiner`.
Use `pcoll.windowing.is_default()` instead so that non-default triggers or
timestamp combiners fall back to the `GroupByKey` branch.
```suggestion
if pcoll.is_bounded and pcoll.windowing.is_default():
```
##########
sdks/python/apache_beam/transforms/combiners.py:
##########
@@ -801,17 +803,98 @@ def add_input(self, accumulator, element, *args,
**kwargs):
]
+class ToSingleElementCollection(CombinerWithoutDefaults):
+ """Base class for combining a PCollection into a single element.
+
+ This is for combining a PCollection into a single element in the cases where
+ there is no value (and significant overhead) in using a combiner as the
+ output is no smaller than its input.
+ """
+ def expand(self, pcoll):
+ raise NotImplementedError
+
+ def _expand(self, pcoll, post_process):
+ if pcoll.is_bounded and pcoll.windowing.windowfn == window.GlobalWindows():
+ # TODO(BEAM-20043): Remove the Map once PCollections used in
+ # side inputs no longer have their elment types mangled by
+ # DataflowRunner.side_input_visitor().
+ side_input = pvalue.AsIter(pcoll | core.Map(lambda x: x))
+
+ timestamped = lambda s: window.TimestampedValue(
+ s, window.GlobalWindow().end)
Review Comment:
**🟠High**: In Beam, the end-of-window timestamp for elements in a window is
`window.max_timestamp()` (`window.end.predecessor()`), not `window.end` (since
windows are half-open `[start, end)`). Both
`GlobalWindows.windowed_value_at_end_of_window` and `OutputAtEndOfWindowImpl`
use `GlobalWindow().max_timestamp()`. Using `GlobalWindow().end` places the
timestamp 1 microsecond past the end of the global window and causes a mismatch
with the `GroupByKey` branch and previous `CombineGlobally` behavior.
```suggestion
s, window.GlobalWindow().max_timestamp())
```
--
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]