Skip to main content

Aggregator

Trait Aggregator 

Source
pub trait Aggregator: Send + Clone {
    type Acc: Accumulator;

    // Required methods
    fn create_accumulator(&self) -> Self::Acc;
    fn extract(
        &self,
        event: &Event,
    ) -> Option<<Self::Acc as Accumulator>::Input>;

    // Provided methods
    fn output_data_type(&self) -> DataType { ... }
    fn output_nullable(&self) -> bool { ... }
    fn extract_batch(
        &self,
        event: &Event,
    ) -> SmallVec<[<Self::Acc as Accumulator>::Input; 4]> { ... }
}
Expand description

Trait for window aggregation functions.

Aggregators define how events are combined within a window. They must be serializable for checkpointing.

Required Associated Types§

Source

type Acc: Accumulator

The accumulator type used by this aggregator.

Required Methods§

Source

fn create_accumulator(&self) -> Self::Acc

Creates a new empty accumulator.

Source

fn extract(&self, event: &Event) -> Option<<Self::Acc as Accumulator>::Input>

Extracts a value from an event to be aggregated.

Returns None if the event should be skipped.

Provided Methods§

Source

fn output_data_type(&self) -> DataType

Returns the Arrow [DataType] for this aggregator’s output.

Defaults to Int64. Override for aggregators that produce different types (e.g., AvgAggregator returns Float64).

Source

fn output_nullable(&self) -> bool

Returns whether the output is nullable (e.g., empty windows produce null).

Defaults to false. Override for aggregators like MIN/MAX/AVG.

Source

fn extract_batch( &self, event: &Event, ) -> SmallVec<[<Self::Acc as Accumulator>::Input; 4]>

Extracts all values from a multi-row batch event.

The default implementation calls extract() and wraps the single result. Override this in aggregators that need to process all rows in a batch (e.g., AvgAggregator).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§