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],
)
| 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. |
| 272 | fn 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. |
| 289 | fn collect_grouping_from_expr( |
no test coverage detected