bingqin2 opened a new pull request, #41602:
URL: https://github.com/apache/beam/pull/41602

   Fixes #41601
   
   `FixedWindows`, `SlidingWindows` and `CalendarWindows` assigned a timestamp 
before their start to a window that does not contain it: for `FixedWindows` and 
`SlidingWindows`, timestamps more than one window before the epoch; for 
`CalendarWindows`, any timestamp before the starting day, month or year 
(including starts set with `withStartingDay`, `withStartingMonth` and 
`withStartingYear`). The issue has examples.
   
   - `FixedWindows.assignWindow` and `SlidingWindows.lastStartFor` subtracted 
`(timestamp + size - offset) % size`, which is negative when `timestamp + size 
- offset` is negative. They now use `Math.floorMod(timestamp - offset, size)`. 
`SlidingWindows.getSideInputWindow` uses `lastStartFor` too.
   - `CalendarWindows` divided `Days.daysBetween` (`monthsBetween`, 
`yearsBetween`) by the number of units. Both round toward zero. The count is 
now rounded down when the start plus that count is after the timestamp, and 
divided with `Math.floorDiv`.
   
   A timestamp whose current window contains it keeps the same window. I 
checked this outside the tests by comparing the old and new start for 2,000,000 
random timestamps and offsets (fixed and sliding) and 300,000 random calendar 
starts, timestamps and time zones: the start changed only where the old window 
did not contain the timestamp, and the new window always contains it.
   
   Testing:
   - New tests in `FixedWindowsTest`, `SlidingWindowsTest` and 
`CalendarWindowsTest` for timestamps before the start. They fail without the 
change.
   - `:sdks:java:core:test` (4338 tests), `:runners:core-java:test` (451) and 
the DirectRunner `validatesRunner` suite (412) pass locally with JDK 17. The 
DirectRunner `needsRunnerTests` suite (1010) has one failure, 
`JavaFilterTransformProviderTest`, which fails the same way on master with JDK 
17: it expects a newer JDK's wording of the `StringIndexOutOfBoundsException` 
message.
   - `CHANGES.md` has a Bugfixes entry.
   
   


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