Convert the components of a USING clause to the USING AST. Returns 'None' if the conditions are not compatible with a USING expression, e.g. non-column expressions or non-matching names.
(
&self,
join_conditions: &[(Expr, Expr)],
)
| 1883 | /// 'None' if the conditions are not compatible with a USING expression, |
| 1884 | /// e.g. non-column expressions or non-matching names. |
| 1885 | fn join_using_to_sql( |
| 1886 | &self, |
| 1887 | join_conditions: &[(Expr, Expr)], |
| 1888 | ) -> Option<ast::JoinConstraint> { |
| 1889 | let mut object_names = Vec::with_capacity(join_conditions.len()); |
| 1890 | for (left, right) in join_conditions { |
| 1891 | match (left, right) { |
| 1892 | ( |
| 1893 | Expr::Column(Column { |
| 1894 | relation: _, |
| 1895 | name: left_name, |
| 1896 | spans: _, |
| 1897 | }), |
| 1898 | Expr::Column(Column { |
| 1899 | relation: _, |
| 1900 | name: right_name, |
| 1901 | spans: _, |
| 1902 | }), |
| 1903 | ) if left_name == right_name => { |
| 1904 | // For example, if the join condition `t1.id = t2.id` |
| 1905 | // this is represented as two columns like `[t1.id, t2.id]` |
| 1906 | // This code forms `id` (without relation name) |
| 1907 | let ident = self.new_ident_quoted_if_needs(left_name.to_string()); |
| 1908 | object_names.push(ast::ObjectName::from(vec![ident])); |
| 1909 | } |
| 1910 | // USING is only valid with matching column names; arbitrary expressions |
| 1911 | // are not allowed |
| 1912 | _ => return None, |
| 1913 | } |
| 1914 | } |
| 1915 | Some(ast::JoinConstraint::Using(object_names)) |
| 1916 | } |
| 1917 | |
| 1918 | /// Convert a join constraint and associated conditions and filter to a SQL AST node |
| 1919 | fn join_constraint_to_sql( |
no test coverage detected