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

Function convert_projection

nodedb-sql/src/planner/select/helpers.rs:15–58  ·  view source on GitHub ↗

Convert SELECT projection items.

(items: &[ast::SelectItem])

Source from the content-addressed store, hash-verified

13
14/// Convert SELECT projection items.
15pub fn convert_projection(items: &[ast::SelectItem]) -> Result<Vec<Projection>> {
16 let mut result = Vec::new();
17 for item in items {
18 match item {
19 ast::SelectItem::UnnamedExpr(expr) => {
20 let sql_expr = convert_expr(expr)?;
21 match &sql_expr {
22 SqlExpr::Column { table, name } => {
23 result.push(Projection::Column(qualified_name(table.as_deref(), name)));
24 }
25 SqlExpr::Wildcard => {
26 result.push(Projection::Star);
27 }
28 _ => {
29 result.push(Projection::Computed {
30 expr: sql_expr,
31 alias: format!("{expr}").to_lowercase(),
32 });
33 }
34 }
35 }
36 ast::SelectItem::ExprWithAlias { expr, alias } => {
37 let sql_expr = convert_expr(expr)?;
38 result.push(Projection::Computed {
39 expr: sql_expr,
40 alias: normalize_ident(alias),
41 });
42 }
43 ast::SelectItem::Wildcard(_) => {
44 result.push(Projection::Star);
45 }
46 ast::SelectItem::QualifiedWildcard(kind, _) => {
47 let table_name = match kind {
48 ast::SelectItemQualifiedWildcardKind::ObjectName(name) => {
49 crate::parser::normalize::normalize_object_name_checked(name)?
50 }
51 _ => String::new(),
52 };
53 result.push(Projection::QualifiedStar(table_name));
54 }
55 }
56 }
57 Ok(result)
58}
59
60/// Build a qualified column reference (`table.name` or just `name`).
61pub fn qualified_name(table: Option<&str>, name: &str) -> String {

Callers 2

plan_join_from_selectFunction · 0.85
plan_selectFunction · 0.85

Calls 5

convert_exprFunction · 0.85
qualified_nameFunction · 0.85
normalize_identFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected