Repository navigation
Conversation
Fixed windows subtracted (ts + size) % size from the timestamp and sliding windows subtracted ts % period. Go's % is negative for a negative left operand, so a timestamp more than one window before the epoch got the next fixed window, and a timestamp before the epoch that is not a multiple of the period got an extra sliding window that does not contain it. Use a floor modulo for both. Timestamps whose window already contained them keep the same windows. Fixes apache#41725
There was a problem hiding this comment.
📋 Review Summary
This PR fixes window assignment in the Go SDK for FixedWindows and SlidingWindows when handling timestamps prior to the Unix epoch. By introducing a floorMod helper to ensure non-negative remainders instead of relying on Go's truncation-toward-zero % operator, negative timestamps are now consistently placed into windows that actually contain them.
🔍 General Feedback
- The mathematical fix in
assignWindows(which also benefitswindowMapper.MapWindowfor side inputs) is clean, accurate, and aligns with the corresponding Java SDK fix in #41602. - Unit test coverage in
window_test.gothoroughly exercises both boundary and non-boundary negative timestamps for fixed windows, sliding windows, and window mapping.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @shunping for label go. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Fixes #41725
In the Go SDK,
window.NewFixedWindowsandwindow.NewSlidingWindowsassigned 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).assignWindowsinexec/window.gosubtracted(ts + size) % sizefor fixed windows andts % periodfor sliding windows. Go's%rounds toward zero, so both were negative there. A newfloorModhelper keeps the remainder in[0, n).windowMapper.MapWindowusesassignWindowstoo, 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:
TestAssignWindow(fixed and sliding, before the epoch and on the boundary) andTestMapWindow(fixed, before the epoch). They fail without the change.go testpasses forcore/runtime/exec/...,core/graph/window/...,runners/prism/internalandtest/integration/primitives.gofmtis clean.CHANGES.mdhas a Bugfixes entry.