MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / extract_grouping_calls

Function extract_grouping_calls

nodedb-sql/src/planner/aggregate.rs:272–286  ·  view source on GitHub ↗

Scan the SELECT projection for `GROUPING(col)` calls and return synthetic `AggregateExpr` entries so the executor can compute the per-set bitmask value. For `GROUPING(col)`, the canonical index of `col` in `canonical_keys` is encoded into the `field` of the resulting `AggregateExpr` (as a decimal string). The executor reads this index and checks the grouping-set bitmask at run time.

(
    items: &[ast::SelectItem],
    canonical_keys: &[SqlExpr],
)

Source from the content-addressed store, hash-verified

270/// encoded into the `field` of the resulting `AggregateExpr` (as a decimal string).
271/// The executor reads this index and checks the grouping-set bitmask at run time.
272fn extract_grouping_calls(
273 items: &[ast::SelectItem],
274 canonical_keys: &[SqlExpr],
275) -> Result<Vec<AggregateExpr>> {
276 let mut out = Vec::new();
277 for item in items {
278 let (expr, alias): (&ast::Expr, String) = match item {
279 ast::SelectItem::UnnamedExpr(expr) => (expr, format!("{expr}")),
280 ast::SelectItem::ExprWithAlias { expr, alias } => (expr, normalize_ident(alias)),
281 _ => continue,
282 };
283 collect_grouping_from_expr(expr, &alias, canonical_keys, &mut out)?;
284 }
285 Ok(out)
286}
287
288/// Recursively collect `GROUPING(col)` calls from an expression.
289fn collect_grouping_from_expr(

Callers 1

plan_aggregateFunction · 0.85

Calls 2

normalize_identFunction · 0.85

Tested by

no test coverage detected