MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / convert_window_spec

Function convert_window_spec

nodedb-sql/src/planner/window/extract.rs:49–186  ·  view source on GitHub ↗
(
    func: &ast::Function,
    alias: &str,
    functions: &FunctionRegistry,
    named: &HashMap<String, &ast::NamedWindowExpr>,
)

Source from the content-addressed store, hash-verified

47}
48
49fn 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 {

Callers 1

extract_window_functionsFunction · 0.85

Calls 13

normalize_identFunction · 0.85
convert_exprFunction · 0.85
flatten_window_specFunction · 0.85
resolve_named_defFunction · 0.85
convert_window_frameFunction · 0.85
joinMethod · 0.80
collectMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
lookupMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected