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