nodedb_physical/physical_plan/aggregate_functions.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! The aggregate functions the generic aggregate accumulates.
4//!
5//! An [`AggregateSpec`](super::AggregateSpec) sent to the generic aggregate
6//! names one of these functions, or the `grouping` pseudo-aggregate. The
7//! planner refuses any other function before it builds the spec.
8
9/// Function names with a generic accumulator.
10pub const GENERIC_AGGREGATE_FUNCTIONS: &[&str] = &[
11 "count",
12 "sum",
13 "avg",
14 "sum_distinct",
15 "avg_distinct",
16 "min",
17 "max",
18 "count_distinct",
19 "stddev",
20 "stddev_pop",
21 "stddev_samp",
22 "variance",
23 "var_pop",
24 "var_samp",
25 "ts_stddev",
26 "approx_count_distinct",
27 "approx_percentile",
28 "approx_topk",
29 "array_agg",
30 "array_agg_distinct",
31 "percentile_cont",
32 "string_agg",
33 "group_concat",
34];
35
36/// Generic aggregates that take a constant parameter beside their input:
37/// the `k` of `approx_topk`, the percentile of `approx_percentile` and
38/// `percentile_cont`. Each spec carries it in
39/// [`AggregateSpec::param`](super::AggregateSpec::param), and a spec
40/// without it is refused.
41pub const PARAMETERIZED_AGGREGATE_FUNCTIONS: &[&str] =
42 &["approx_topk", "approx_percentile", "percentile_cont"];
43
44/// The constant parameter of a parameterized aggregate.
45#[derive(
46 Debug,
47 Clone,
48 Copy,
49 PartialEq,
50 serde::Serialize,
51 serde::Deserialize,
52 zerompk::ToMessagePack,
53 zerompk::FromMessagePack,
54)]
55pub enum AggregateParam {
56 /// The fraction of `approx_percentile` / `percentile_cont`, in `[0, 1]`.
57 Percentile { fraction: f64 },
58 /// The `k` of `approx_topk`, at least 1.
59 TopK { k: u32 },
60}