Skip to main content

Module aggregation

Module aggregation 

Source
Expand description

Aggregation module for computing statistics over streaming data

This module provides a comprehensive set of aggregators for computing various statistics over streaming data. All aggregators support:

  • Incremental updates: Feed values one at a time
  • Batch updates: Feed multiple values at once
  • Accumulator merging: Combine results from distributed processing
  • State serialization: Persist and restore aggregator state

§Available Aggregators

§Examples

§Basic Usage

use processor::aggregation::{Aggregator, AverageAggregator};

let mut agg = AverageAggregator::new();
agg.update(10.0).unwrap();
agg.update(20.0).unwrap();
agg.update(30.0).unwrap();

assert_eq!(agg.finalize().unwrap(), 20.0);

§Distributed Processing

use processor::aggregation::{Aggregator, SumAggregator};

// Process data in parallel
let mut agg1 = SumAggregator::new();
agg1.update_batch(&[1.0, 2.0, 3.0]).unwrap();

let mut agg2 = SumAggregator::new();
agg2.update_batch(&[4.0, 5.0, 6.0]).unwrap();

// Merge results
let acc2 = agg2.accumulator();
agg1.merge(acc2).unwrap();

assert_eq!(agg1.finalize().unwrap(), 21.0);

§Composite Aggregation

use processor::aggregation::CompositeAggregator;

let mut composite = CompositeAggregator::new();
composite
    .add_count("request_count")
    .add_avg("avg_latency")
    .add_p95("p95_latency")
    .add_stddev("stddev_latency");

// Feed data
for latency in vec![100.0, 150.0, 200.0, 250.0, 300.0] {
    composite.update(latency).unwrap();
}

// Get all results at once
let results = composite.finalize().unwrap();
println!("Count: {}", results.get_count("request_count").unwrap());
println!("Avg: {:.2}", results.get_value("avg_latency").unwrap());
println!("P95: {:.2}", results.get_value("p95_latency").unwrap());

Modules§

statistics
Enhanced statistical utilities for stream processing

Structs§

AggregationResult
Results from a composite aggregation
AverageAccumulator
Accumulator for average aggregation
AverageAggregator
Average aggregator - computes the mean of all values
CompositeAggregator
A composite aggregator that runs multiple aggregations in parallel
CountAccumulator
Accumulator for count aggregation
CountAggregator
Count aggregator - counts the number of values
MaxAccumulator
Accumulator for max aggregation
MaxAggregator
Max aggregator - tracks the maximum value seen
MinAccumulator
Accumulator for min aggregation
MinAggregator
Min aggregator - tracks the minimum value seen
PercentileAccumulator
Accumulator for percentile aggregation
PercentileAggregator
Percentile aggregator - computes percentiles (p50, p95, p99, etc.)
StandardDeviationAggregator
Standard deviation aggregator - computes sample standard deviation
StdDevAccumulator
Accumulator for standard deviation aggregation
SumAccumulator
Accumulator for sum aggregation
SumAggregator
Sum aggregator - computes the sum of all values

Traits§

Aggregator
Core trait for all aggregators
ToF64
Helper trait for converting values to f64 for numeric aggregations