Convert SELECT projection items.
(items: &[ast::SelectItem])
| 13 | |
| 14 | /// Convert SELECT projection items. |
| 15 | pub 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`). |
| 61 | pub fn qualified_name(table: Option<&str>, name: &str) -> String { |
no test coverage detected