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
+70Lines changed: 70 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -593,6 +593,76 @@ if __name__ == '__main__':
593
593
```
594
594
595
595
596
+
### Early window expiration with triggers
597
+
!!! info New in v3.24.0
598
+
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
+
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
+
603
+
**How it works**:
604
+
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.
612
+
613
+
**Example with after_update**:
614
+
615
+
```python
616
+
from typing import Any
617
+
618
+
from datetime import timedelta
619
+
from quixstreams import Application
620
+
621
+
app = Application(...)
622
+
sdf = app.dataframe(...)
623
+
624
+
625
+
deftrigger_on_threshold(
626
+
aggregated: int, value: Any, key: Any, timestamp: int, headers: Any
627
+
) -> bool:
628
+
"""
629
+
Expire the window early when the sum exceeds 1000.
630
+
"""
631
+
return aggregated >1000
632
+
633
+
634
+
# Define a 1-hour tumbling window with early expiration trigger
0 commit comments