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

   Fixes #41725
   
   In the Go SDK, `window.NewFixedWindows` and `window.NewSlidingWindows` 
assigned a timestamp before the epoch to a window that does not contain it: for 
fixed windows, timestamps more than one window before the epoch; for sliding 
windows, any timestamp before the epoch that is not a multiple of the period. 
The issue has examples. This is the Go side of #41601 (Java, PR #41602).
   
   `assignWindows` in `exec/window.go` subtracted `(ts + size) % size` for 
fixed windows and `ts % period` for sliding windows. Go's `%` rounds toward 
zero, so both were negative there. A new `floorMod` helper keeps the remainder 
in `[0, n)`. `windowMapper.MapWindow` uses `assignWindows` too, so side input 
windows are mapped correctly as well.
   
   A timestamp whose current windows contain it keeps the same windows. I 
checked this outside the tests by comparing the old and new results for 
2,000,000 random timestamps, sizes and periods: the windows changed only where 
an old window did not contain the timestamp, every new window contains it and 
starts at a multiple of the size or period, and sliding windows have the 
expected count.
   
   Testing:
   - New cases in `TestAssignWindow` (fixed and sliding, before the epoch and 
on the boundary) and `TestMapWindow` (fixed, before the epoch). They fail 
without the change.
   - `go test` passes for `core/runtime/exec/...`, `core/graph/window/...`, 
`runners/prism/internal` and `test/integration/primitives`. `gofmt` is clean.
   - `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]

  • [PR] [Go SDK] Fix fixed and sl... bingqin2 (via GitHub) via github

Reply via email to