- Emit on update: This policy calculates and emits partial window results even before the window is closed.
- Emit on window close: This policy generates a final result when the window closes and will remain unchanged thereafter.
- Emit on update: With this policy, the aggregation operator emits a new
count(*)
result downstream whenever each barrier passes (default interval is 1 second). This updated count is then reflected in the materialized view or outputted to external systems. - Emit on window close: When the watermark defined on
event_time
surpasses the end time of a time window, the aggregation operator emits the final immutable aggregation result downstream. This result represents the complete aggregation for the window and is not subject to further changes.
- When the downstream system of the sink is append-only, such as Kafka or S3, and we prefer to write the result only once it is finalized, rather than performing multiple writes and updates.
- When certain calculations in the query cannot efficiently handle incremental updates, such as percentile calculations, and we want to trigger the calculation only when the window closes for better performance.
EMIT ON WINDOW CLOSE
clause. Additionally, a watermark must be defined on the data source, as it determines when the window can be closed. For a more detailed explanation of watermarks, please refer to Watermarks.
We can modify the query above to use emit-on-window-close semantics:
window_count
results will no longer include any partial aggregation results from the most recent window. Instead, a final result will only be delivered when the event_time
watermark surpasses the end time of the window.
Changed in v2.3: Support grouping by
window_start
and window_end
at the same time in emit-on-window-close queries.