nodedb_query/agg_key.rs
1//! Canonical aggregate key generation.
2//!
3//! A single source of truth for naming aggregate output fields.
4//! Used by the SQL planner (HAVING filter field names) and the
5//! Data Plane aggregate handler (result row keys).
6//!
7//! Examples:
8//! `canonical_agg_key("count", "*")` → `"count(*)"`
9//! `canonical_agg_key("sum", "price")` → `"sum(price)"`
10//! `canonical_agg_key("avg", "score")` → `"avg(score)"`
11
12/// Build the canonical key for an aggregate result field.
13///
14/// Format: `"{function}({arg})"` — e.g. `count(*)`, `sum(price)`.
15/// This MUST be used everywhere an aggregate field is named:
16/// - Aggregate result row keys (Data Plane)
17/// - HAVING filter field names (SQL planner)
18/// - Post-aggregation field references (Control Plane)
19#[inline]
20pub fn canonical_agg_key(function: &str, arg: &str) -> String {
21 format!("{function}({arg})")
22}