Convert a join constraint and associated conditions and filter to a SQL AST node
(
&self,
constraint: JoinConstraint,
conditions: &[(Expr, Expr)],
filter: Option<&Expr>,
)
| 1917 | |
| 1918 | /// Convert a join constraint and associated conditions and filter to a SQL AST node |
| 1919 | fn join_constraint_to_sql( |
| 1920 | &self, |
| 1921 | constraint: JoinConstraint, |
| 1922 | conditions: &[(Expr, Expr)], |
| 1923 | filter: Option<&Expr>, |
| 1924 | ) -> Result<ast::JoinConstraint> { |
| 1925 | match (constraint, conditions, filter) { |
| 1926 | // No constraints |
| 1927 | (JoinConstraint::On | JoinConstraint::Using, [], None) => { |
| 1928 | Ok(ast::JoinConstraint::None) |
| 1929 | } |
| 1930 | |
| 1931 | (JoinConstraint::Using, conditions, None) => { |
| 1932 | match self.join_using_to_sql(conditions) { |
| 1933 | Some(using) => Ok(using), |
| 1934 | // As above, this should not be reachable from parsed SQL, |
| 1935 | // but a user could create this; we "downgrade" to ON. |
| 1936 | None => self.join_conditions_to_sql_on(conditions, None), |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | // Two cases here: |
| 1941 | // 1. Straightforward ON case, with possible equi-join conditions |
| 1942 | // and additional filters |
| 1943 | // 2. USING with additional filters; we "downgrade" to ON, because |
| 1944 | // you can't use USING with arbitrary filters. (This should not |
| 1945 | // be accessible from parsed SQL, but may have been a |
| 1946 | // custom-built JOIN by a user.) |
| 1947 | (JoinConstraint::On | JoinConstraint::Using, conditions, filter) => { |
| 1948 | self.join_conditions_to_sql_on(conditions, filter) |
| 1949 | } |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | // Convert a list of equi0join conditions and an optional filter to a SQL ON |
| 1954 | // AST node, with the equi-join conditions and the filter merged into a |
no test coverage detected