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

Function convert_function_depth

nodedb-sql/src/resolver/expr/functions.rs:11–91  ·  view source on GitHub ↗
(func: &ast::Function, depth: &mut usize)

Source from the content-addressed store, hash-verified

9use super::convert::convert_expr_depth;
10
11pub(super) fn convert_function_depth(func: &ast::Function, depth: &mut usize) -> Result<SqlExpr> {
12 // Intercept PG FTS surface functions and lower them to pg_* internal names
13 // before the generic path runs.
14 if func.name.0.len() == 1 {
15 let raw_name = match &func.name.0[0] {
16 ast::ObjectNamePart::Identifier(ident) => ident.value.to_ascii_lowercase(),
17 _ => String::new(),
18 };
19 if let Some(expr) = intercept_fts_function(&raw_name, func, depth)? {
20 return Ok(expr);
21 }
22 }
23
24 if func.name.0.len() > 1 {
25 let qualified: String = func
26 .name
27 .0
28 .iter()
29 .map(|p| match p {
30 ast::ObjectNamePart::Identifier(ident) => ident.value.clone(),
31 _ => String::new(),
32 })
33 .collect::<Vec<_>>()
34 .join(".");
35 return Err(SqlError::Unsupported {
36 detail: format!("schema-qualified function name '{qualified}': {SCHEMA_QUALIFIED_MSG}"),
37 });
38 }
39 let name = func
40 .name
41 .0
42 .iter()
43 .map(|p| match p {
44 ast::ObjectNamePart::Identifier(ident) => normalize_ident(ident),
45 _ => String::new(),
46 })
47 .collect::<Vec<_>>()
48 .join(".");
49
50 let args = match &func.args {
51 ast::FunctionArguments::None => Vec::new(),
52 ast::FunctionArguments::Subquery(_) => {
53 return Err(SqlError::Unsupported {
54 detail: "subquery in function args".into(),
55 });
56 }
57 ast::FunctionArguments::List(arg_list) => arg_list
58 .args
59 .iter()
60 .filter_map(|a| match a {
61 ast::FunctionArg::Unnamed(ast::FunctionArgExpr::Expr(e)) => {
62 Some(convert_expr_depth(e, depth))
63 }
64 ast::FunctionArg::Unnamed(ast::FunctionArgExpr::Wildcard) => {
65 Some(Ok(SqlExpr::Wildcard))
66 }
67 ast::FunctionArg::Named {
68 arg: ast::FunctionArgExpr::Expr(e),

Callers 1

convert_expr_innerFunction · 0.85

Calls 7

intercept_fts_functionFunction · 0.85
normalize_identFunction · 0.85
convert_expr_depthFunction · 0.85
joinMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected