Skip to main content

Module session_window

Module session_window 

Source
Expand description

§Session Window Operators

Implementation of session windows for stream processing.

Session windows are dynamic windows that group events by activity periods separated by gaps. Unlike tumbling and sliding windows which have fixed boundaries, session windows grow with activity and close after inactivity.

§Key Characteristics

  • Dynamic boundaries: Sessions start with the first event and extend with each new event within the gap period
  • Per-key tracking: Each key maintains independent session state
  • Gap-based closure: Sessions close when no events arrive within the gap
  • Session merging: Late data can merge previously separate sessions

§Example

Gap: 30 seconds

Events: [t=0] [t=10] [t=20]  ...gap...  [t=100] [t=110]
        |<---- Session 1 ---->|          |<- Session 2 ->|
        [0, 50)                          [100, 140)

§Usage

use laminar_core::operator::session_window::SessionWindowOperator;
use laminar_core::operator::window::CountAggregator;
use std::time::Duration;

// Create a session window with 30-second gap
let operator = SessionWindowOperator::new(
    Duration::from_secs(30),    // gap timeout
    CountAggregator::new(),
    Duration::from_secs(60),    // allowed lateness
);

Structs§

ArchivedSessionState
An archived SessionState
SessionMetrics
Session metrics for monitoring.
SessionState
Session state tracking start/end times and key.
SessionStateResolver
The resolver for an archived SessionState
SessionWindowOperator
Session window operator.