micromegas_datafusion_extensions/histogram/
sum_histograms_udaf.rs

1use super::{accumulator::HistogramAccumulator, histogram_udaf::make_histogram_arrow_type};
2use datafusion::{
3    error::DataFusionError,
4    logical_expr::{Accumulator, AggregateUDF, Volatility, function::AccumulatorArgs},
5    prelude::*,
6};
7use std::sync::Arc;
8
9fn make_empty_accumulator(_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>, DataFusionError> {
10    Ok(Box::new(HistogramAccumulator::new_non_configured()))
11}
12
13/// Creates a user-defined aggregate function to sum histograms.
14pub fn sum_histograms_udaf() -> AggregateUDF {
15    create_udaf(
16        "sum_histograms",
17        vec![make_histogram_arrow_type()],
18        Arc::new(make_histogram_arrow_type()),
19        Volatility::Immutable,
20        Arc::new(&make_empty_accumulator),
21        Arc::new(vec![make_histogram_arrow_type()]),
22    )
23}