Extract window function specifications from a SELECT's projection.
(
select: &ast::Select,
functions: &FunctionRegistry,
)
| 26 | |
| 27 | /// Extract window function specifications from a SELECT's projection. |
| 28 | pub fn extract_window_functions( |
| 29 | select: &ast::Select, |
| 30 | functions: &FunctionRegistry, |
| 31 | ) -> Result<Vec<WindowSpec>> { |
| 32 | let named = collect_named_windows(&select.named_window)?; |
| 33 | let mut specs = Vec::new(); |
| 34 | for item in &select.projection { |
| 35 | let (expr, alias) = match item { |
| 36 | ast::SelectItem::UnnamedExpr(e) => (e, format!("{e}")), |
| 37 | ast::SelectItem::ExprWithAlias { expr, alias } => (expr, normalize_ident(alias)), |
| 38 | _ => continue, |
| 39 | }; |
| 40 | if let ast::Expr::Function(func) = expr |
| 41 | && func.over.is_some() |
| 42 | { |
| 43 | specs.push(convert_window_spec(func, &alias, functions, &named)?); |
| 44 | } |
| 45 | } |
| 46 | Ok(specs) |
| 47 | } |
| 48 | |
| 49 | fn convert_window_spec( |
| 50 | func: &ast::Function, |