(&self, args: &[Expr])
| 720 | } |
| 721 | |
| 722 | fn get_field_to_sql(&self, args: &[Expr]) -> Result<ast::Expr> { |
| 723 | if args.len() < 2 { |
| 724 | return internal_err!( |
| 725 | "get_field must have at least 2 arguments, got {}", |
| 726 | args.len() |
| 727 | ); |
| 728 | } |
| 729 | |
| 730 | // Extract all field names (args[1..]) |
| 731 | let mut fields = Vec::with_capacity(args.len() - 1); |
| 732 | for arg in &args[1..] { |
| 733 | let field = match arg { |
| 734 | Expr::Literal(lit, _) => self.new_ident_quoted_if_needs(lit.to_string()), |
| 735 | _ => { |
| 736 | return internal_err!( |
| 737 | "get_field expects field arguments to be strings, but received: {:?}", |
| 738 | arg |
| 739 | ); |
| 740 | } |
| 741 | }; |
| 742 | fields.push(field); |
| 743 | } |
| 744 | |
| 745 | match &args[0] { |
| 746 | Expr::Column(col) => { |
| 747 | let mut id = match self.col_to_sql(col)? { |
| 748 | ast::Expr::Identifier(ident) => vec![ident], |
| 749 | ast::Expr::CompoundIdentifier(idents) => idents, |
| 750 | other => { |
| 751 | return internal_err!( |
| 752 | "expected col_to_sql to return an Identifier or CompoundIdentifier, but received: {:?}", |
| 753 | other |
| 754 | ); |
| 755 | } |
| 756 | }; |
| 757 | id.extend(fields); |
| 758 | Ok(ast::Expr::CompoundIdentifier(id)) |
| 759 | } |
| 760 | Expr::ScalarFunction(struct_expr) => { |
| 761 | let root = self |
| 762 | .scalar_function_to_sql(struct_expr.func.name(), &struct_expr.args)?; |
| 763 | let access_chain = fields |
| 764 | .into_iter() |
| 765 | .map(|field| ast::AccessExpr::Dot(ast::Expr::Identifier(field))) |
| 766 | .collect(); |
| 767 | Ok(ast::Expr::CompoundFieldAccess { |
| 768 | root: Box::new(root), |
| 769 | access_chain, |
| 770 | }) |
| 771 | } |
| 772 | _ => { |
| 773 | internal_err!( |
| 774 | "get_field expects first argument to be column or scalar function, but received: {:?}", |
| 775 | &args[0] |
| 776 | ) |
| 777 | } |
| 778 | } |
| 779 | } |
no test coverage detected