Resolve a named-window reference to its concrete `WindowSpec`, following `WINDOW a AS b` aliases. `seen` tracks the alias chain for cycle detection. Errors on undefined names and cycles.
(
name: &str,
named: &HashMap<String, &'a ast::NamedWindowExpr>,
seen: &mut Vec<String>,
)
| 45 | /// `WINDOW a AS b` aliases. `seen` tracks the alias chain for cycle |
| 46 | /// detection. Errors on undefined names and cycles. |
| 47 | pub(super) fn resolve_named_def<'a>( |
| 48 | name: &str, |
| 49 | named: &HashMap<String, &'a ast::NamedWindowExpr>, |
| 50 | seen: &mut Vec<String>, |
| 51 | ) -> Result<&'a ast::WindowSpec> { |
| 52 | let expr = *named.get(name).ok_or_else(|| SqlError::InvalidFunction { |
| 53 | detail: format!("window '{name}' is not defined in the WINDOW clause"), |
| 54 | })?; |
| 55 | match expr { |
| 56 | ast::NamedWindowExpr::WindowSpec(spec) => Ok(spec), |
| 57 | ast::NamedWindowExpr::NamedWindow(other) => { |
| 58 | let other = normalize_ident(other); |
| 59 | if seen.contains(&other) { |
| 60 | return Err(SqlError::Unsupported { |
| 61 | detail: format!("circular WINDOW definition involving '{other}'"), |
| 62 | }); |
| 63 | } |
| 64 | seen.push(other.clone()); |
| 65 | resolve_named_def(&other, named, seen) |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /// Flatten an inline-or-named `WindowSpec`, merging in any referenced window |
| 71 | /// per the SQL inheritance rules (see module docs). |
no test coverage detected