pub struct TumblingWindowOperator<A: Aggregator> { /* private fields */ }Expand description
Tumbling window operator.
Processes events through non-overlapping, fixed-size time windows.
Events are assigned to windows based on their timestamps, aggregated,
and results are emitted based on the configured EmitStrategy.
§Emit Strategies
OnWatermark(default): Emit when watermark passes window endPeriodic: Emit intermediate results at intervals, final on watermarkOnUpdate: Emit after every state update
§Late Data Handling
Events that arrive after window_end + allowed_lateness are considered late.
Their behavior is controlled by LateDataConfig:
- Drop the event (default)
- Route to a named side output for separate processing
§State Management
Window state is stored in the operator context’s state store using prefixed keys:
win:<window_id>- Accumulator statemeta:<window_id>- Window metadata (registration status, etc.)
§Watermark Triggering
Windows are triggered when the watermark advances past window_end + allowed_lateness.
This ensures late data within the grace period is still processed.
Implementations§
Source§impl<A: Aggregator> TumblingWindowOperator<A>where
A::Acc: Archive + for<'a> RkyvSerialize<HighSerializer<AlignedVec, ArenaHandle<'a>, Error>>,
<A::Acc as Archive>::Archived: for<'a> CheckBytes<HighValidator<'a, Error>> + RkyvDeserialize<A::Acc, HighDeserializer<Error>>,
impl<A: Aggregator> TumblingWindowOperator<A>where
A::Acc: Archive + for<'a> RkyvSerialize<HighSerializer<AlignedVec, ArenaHandle<'a>, Error>>,
<A::Acc as Archive>::Archived: for<'a> CheckBytes<HighValidator<'a, Error>> + RkyvDeserialize<A::Acc, HighDeserializer<Error>>,
Sourcepub fn new(
assigner: TumblingWindowAssigner,
aggregator: A,
allowed_lateness: Duration,
) -> Self
pub fn new( assigner: TumblingWindowAssigner, aggregator: A, allowed_lateness: Duration, ) -> Self
Sourcepub fn with_id(
assigner: TumblingWindowAssigner,
aggregator: A,
allowed_lateness: Duration,
operator_id: String,
) -> Self
pub fn with_id( assigner: TumblingWindowAssigner, aggregator: A, allowed_lateness: Duration, operator_id: String, ) -> Self
Creates a new tumbling window operator with a custom operator ID.
§Panics
Panics if allowed lateness does not fit in i64.
Sourcepub fn set_emit_strategy(&mut self, strategy: EmitStrategy)
pub fn set_emit_strategy(&mut self, strategy: EmitStrategy)
Sets the emit strategy for this window operator.
§Arguments
strategy- The emit strategy to use
§Example
use laminar_core::operator::window::{
TumblingWindowAssigner, TumblingWindowOperator, CountAggregator, EmitStrategy,
};
use std::time::Duration;
let assigner = TumblingWindowAssigner::new(Duration::from_secs(60));
let mut operator = TumblingWindowOperator::new(
assigner,
CountAggregator::new(),
Duration::from_secs(5),
);
// Emit every 10 seconds instead of waiting for watermark
operator.set_emit_strategy(EmitStrategy::Periodic(Duration::from_secs(10)));Sourcepub fn emit_strategy(&self) -> &EmitStrategy
pub fn emit_strategy(&self) -> &EmitStrategy
Returns the current emit strategy.
Sourcepub fn set_late_data_config(&mut self, config: LateDataConfig)
pub fn set_late_data_config(&mut self, config: LateDataConfig)
Sets the late data handling configuration.
§Arguments
config- The late data configuration to use
§Example
use laminar_core::operator::window::{
TumblingWindowAssigner, TumblingWindowOperator, CountAggregator, LateDataConfig,
};
use std::time::Duration;
let assigner = TumblingWindowAssigner::new(Duration::from_secs(60));
let mut operator = TumblingWindowOperator::new(
assigner,
CountAggregator::new(),
Duration::from_secs(5),
);
// Route late events to a side output
operator.set_late_data_config(LateDataConfig::with_side_output("late_events".to_string()));Sourcepub fn late_data_config(&self) -> &LateDataConfig
pub fn late_data_config(&self) -> &LateDataConfig
Returns the current late data configuration.
Sourcepub fn late_data_metrics(&self) -> &LateDataMetrics
pub fn late_data_metrics(&self) -> &LateDataMetrics
Returns the late data metrics.
Use this to monitor late data behavior and set up alerts.
Sourcepub fn reset_late_data_metrics(&mut self)
pub fn reset_late_data_metrics(&mut self)
Resets the late data metrics counters.
Sourcepub fn assigner(&self) -> &TumblingWindowAssigner
pub fn assigner(&self) -> &TumblingWindowAssigner
Returns the window assigner.
Sourcepub fn allowed_lateness_ms(&self) -> i64
pub fn allowed_lateness_ms(&self) -> i64
Returns the allowed lateness in milliseconds.
Trait Implementations§
Source§impl<A: Aggregator> Operator for TumblingWindowOperator<A>where
A::Acc: 'static + Archive + for<'a> RkyvSerialize<HighSerializer<AlignedVec, ArenaHandle<'a>, Error>>,
<A::Acc as Archive>::Archived: for<'a> CheckBytes<HighValidator<'a, Error>> + RkyvDeserialize<A::Acc, HighDeserializer<Error>>,
impl<A: Aggregator> Operator for TumblingWindowOperator<A>where
A::Acc: 'static + Archive + for<'a> RkyvSerialize<HighSerializer<AlignedVec, ArenaHandle<'a>, Error>>,
<A::Acc as Archive>::Archived: for<'a> CheckBytes<HighValidator<'a, Error>> + RkyvDeserialize<A::Acc, HighDeserializer<Error>>,
Source§fn process(&mut self, event: &Event, ctx: &mut OperatorContext<'_>) -> OutputVec
fn process(&mut self, event: &Event, ctx: &mut OperatorContext<'_>) -> OutputVec
Source§fn on_timer(&mut self, timer: Timer, ctx: &mut OperatorContext<'_>) -> OutputVec
fn on_timer(&mut self, timer: Timer, ctx: &mut OperatorContext<'_>) -> OutputVec
Source§fn checkpoint(&self) -> OperatorState
fn checkpoint(&self) -> OperatorState
Source§fn restore(&mut self, state: OperatorState) -> Result<(), OperatorError>
fn restore(&mut self, state: OperatorState) -> Result<(), OperatorError>
Auto Trait Implementations§
impl<A> Freeze for TumblingWindowOperator<A>where
A: Freeze,
impl<A> RefUnwindSafe for TumblingWindowOperator<A>
impl<A> Send for TumblingWindowOperator<A>
impl<A> Sync for TumblingWindowOperator<A>
impl<A> Unpin for TumblingWindowOperator<A>
impl<A> UnwindSafe for TumblingWindowOperator<A>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.