You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/windowing.md
+33-10Lines changed: 33 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -596,19 +596,21 @@ if __name__ == '__main__':
596
596
### Early window expiration with triggers
597
597
!!! info New in v3.24.0
598
598
599
-
To expire windows before their natural expiration time based on custom conditions, you can pass the `on_update` callback to `.tumbling_window()` and `.hopping_window()` methods.
599
+
To expire windows before their natural expiration time based on custom conditions, you can pass `before_update` or `after_update` callbacks to `.tumbling_window()` and `.hopping_window()` methods.
600
600
601
601
This is useful when you want to emit results as soon as certain conditions are met, rather than waiting for the window to close naturally.
602
602
603
603
**How it works**:
604
604
605
-
- The `on_update` callback is invoked every time a window is updated with a new value.
606
-
- It receives `old_value` and `new_value` - the raw aggregated values before and after the update.
607
-
- For `collect()` operations, it receives lists of collected values.
608
-
- If the callback returns `True`, the window is immediately expired and emitted downstream.
609
-
- The expired window is removed from state, but may be "resurrected" if new data arrives within its time range before natural expiration.
605
+
- The `before_update` callback is invoked before the window aggregation is updated with a new value.
606
+
- The `after_update` callback is invoked after the window aggregation has been updated with a new value.
607
+
- Both callbacks receive: `aggregated` (current or updated aggregated value), `value` (incoming value), `key`, `timestamp`, and `headers`.
608
+
- For `collect()` operations without aggregation, `aggregated` contains the list of collected values.
609
+
- If either callback returns `True`, the window is immediately expired and emitted downstream.
610
+
- The window metadata is deleted from state, but collected values (if using `.collect()`) remain until natural expiration.
611
+
- This means a triggered window can be "resurrected" if new data arrives within its time range - a new window will be created with the previously collected values still present.
0 commit comments