(
func: &ast::Function,
alias: &str,
functions: &FunctionRegistry,
named: &HashMap<String, &ast::NamedWindowExpr>,
)
| 47 | } |
| 48 | |
| 49 | fn convert_window_spec( |
| 50 | func: &ast::Function, |
| 51 | alias: &str, |
| 52 | functions: &FunctionRegistry, |
| 53 | named: &HashMap<String, &ast::NamedWindowExpr>, |
| 54 | ) -> Result<WindowSpec> { |
| 55 | if func.name.0.len() > 1 { |
| 56 | let qualified: String = func |
| 57 | .name |
| 58 | .0 |
| 59 | .iter() |
| 60 | .map(|p| match p { |
| 61 | ast::ObjectNamePart::Identifier(ident) => ident.value.clone(), |
| 62 | _ => String::new(), |
| 63 | }) |
| 64 | .collect::<Vec<_>>() |
| 65 | .join("."); |
| 66 | return Err(SqlError::Unsupported { |
| 67 | detail: format!( |
| 68 | "schema-qualified window function name '{qualified}': {SCHEMA_QUALIFIED_MSG}" |
| 69 | ), |
| 70 | }); |
| 71 | } |
| 72 | let name = func |
| 73 | .name |
| 74 | .0 |
| 75 | .iter() |
| 76 | .map(|p| match p { |
| 77 | ast::ObjectNamePart::Identifier(ident) => normalize_ident(ident), |
| 78 | _ => String::new(), |
| 79 | }) |
| 80 | .collect::<Vec<_>>() |
| 81 | .join("."); |
| 82 | |
| 83 | // Reject unknown names at plan time. PostgreSQL permits aggregates as |
| 84 | // windows, so accept either Window or Aggregate categories. |
| 85 | match functions.lookup(&name).map(|m| m.category) { |
| 86 | Some(FunctionCategory::Window) | Some(FunctionCategory::Aggregate) => {} |
| 87 | Some(FunctionCategory::Scalar) => { |
| 88 | return Err(SqlError::InvalidFunction { |
| 89 | detail: format!( |
| 90 | "function '{name}() OVER ()' does not exist as a window function \ |
| 91 | (it is a scalar function)" |
| 92 | ), |
| 93 | }); |
| 94 | } |
| 95 | None => { |
| 96 | return Err(SqlError::InvalidFunction { |
| 97 | detail: format!("function '{name}() OVER ()' does not exist"), |
| 98 | }); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | let args = match &func.args { |
| 103 | ast::FunctionArguments::List(args) => args |
| 104 | .args |
| 105 | .iter() |
| 106 | .filter_map(|a| match a { |
no test coverage detected