github-actions[bot] commented on code in PR #41135:
URL: https://github.com/apache/beam/pull/41135#discussion_r4517463517
##########
sdks/python/apache_beam/transforms/window.py:
##########
@@ -255,6 +255,13 @@ class IntervalWindow(windowed_value._IntervalWindowBase,
BoundedWindow):
start: Start of window as seconds since Unix epoch.
end: End of window as seconds since Unix epoch.
"""
+ @classmethod
+ def from_micros(cls, start_micros: int, end_micros: int) -> 'IntervalWindow':
+ w = cls(None, None)
+ w._start_micros = start_micros
+ w._end_micros = end_micros
Review Comment:
**🟠High**: When `apache_beam.utils.windowed_value` is compiled with Cython
(`windowed_value.pxd`), `_start_micros` and `_end_micros` are `cdef public
int64_t` fields (`[-9223372036854775808, 9223372036854775807]`). Because
`MIN_TIMESTAMP.micros` (`-9223372036854775000`) is only 808 microseconds above
`INT64_MIN`, assigning windows to elements at `MIN_TIMESTAMP` (such as elements
emitted by `Impulse()` or `Create()` before timestamp assignment, e.g.,
`Create(...) | WindowInto(FixedWindows(60))` or `SlidingWindows(60, 10)`)
produces `start_micros < INT64_MIN`. Similarly, `Sessions.assign` at
`MAX_TIMESTAMP` produces `end_micros > INT64_MAX`.
Previously, `IntervalWindow(start, end)` delegated to
`_IntervalWindowBase.__init__`, which explicitly caught `OverflowError` on
`self._start_micros` / `self._end_micros` assignment and clamped them to
`[MIN_TIMESTAMP.micros, MAX_TIMESTAMP.micros]` while preserving `_start_object`
/ `_end_object` (`sdks/python/apache_beam/utils/windowed_value.py:397-412`). In
Cython builds, `IntervalWindow.from_micros` will raise an unhandled
`OverflowError: Python int too large to convert to C long` unless it similarly
catches `OverflowError`:
```python
@classmethod
def from_micros(cls, start_micros: int, end_micros: int) ->
'IntervalWindow':
w = cls(None, None)
try:
w._start_micros = start_micros
except OverflowError:
w._start_object = Timestamp(micros=start_micros)
w._start_micros = (
MIN_TIMESTAMP.micros if start_micros < 0 else MAX_TIMESTAMP.micros)
try:
w._end_micros = end_micros
except OverflowError:
w._end_object = Timestamp(micros=end_micros)
w._end_micros = (
MIN_TIMESTAMP.micros if end_micros < 0 else MAX_TIMESTAMP.micros)
return w
```
--
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]