Extract every aggregate function call from `expr`, binding each to the given output `alias`. Nested aggregates (e.g. `SUM(AVG(x))`, which is illegal SQL in Postgres and most other systems) are reported as a planner error rather than silently double-extracted.
(
expr: &Expr,
alias: &str,
functions: &FunctionRegistry,
)
| 49 | /// which is illegal SQL in Postgres and most other systems) are |
| 50 | /// reported as a planner error rather than silently double-extracted. |
| 51 | pub fn extract_aggregates( |
| 52 | expr: &Expr, |
| 53 | alias: &str, |
| 54 | functions: &FunctionRegistry, |
| 55 | ) -> Result<Vec<AggregateExpr>> { |
| 56 | let mut extractor = AggregateExtractor { |
| 57 | functions, |
| 58 | alias, |
| 59 | inside_aggregate: 0, |
| 60 | out: Vec::new(), |
| 61 | error: None, |
| 62 | }; |
| 63 | let _ = expr.visit(&mut extractor); |
| 64 | if let Some(e) = extractor.error { |
| 65 | return Err(e); |
| 66 | } |
| 67 | Ok(extractor.out) |
| 68 | } |
| 69 | |
| 70 | // ── Detector ──────────────────────────────────────────────────────── |
| 71 |
no outgoing calls