Properly handle mixed implicit and explicit joins

Parse a query like

    SELECT * FROM a NATURAL JOIN b, c NATURAL JOIN d

as the SQL specification requires, i.e.:

    from: [
        TableReference {
            relation: TableFactor::Table("a"),
            joins: [Join {
                relation: TableFactor::Table("b"),
                join_operator: JoinOperator::Natural,
            }]
        },
        TableReference {
            relation: TableFactor::Table("c"),
            joins: [Join {
                relation: TableFactor::Table("d"),
                join_operator: JoinOperator::Natural,
            }]
        }
    ]

Previously we were parsing such queries as

    relation: TableFactor::Table("a"),
    joins: [
        Join {
            relation: TableFactor::Table("b"),
            join_operator: JoinOperator::Natural,
        },
        Join {
            relation: TableFactor::Table("c"),
            join_operator: JoinOperator::Implicit,
        },
        Join {
            relation: TableFactor::Table("d"),
            join_operator: JoinOperator::Natural,
        },
    ]

which did not make the join hierarchy clear.
This commit is contained in:
Nikhil Benesch 2019-06-07 23:45:26 -04:00
parent 518c8833d2
commit b841dccc2c
No known key found for this signature in database
GPG key ID: FCF98542083C5A69
6 changed files with 219 additions and 164 deletions

View file

@ -109,9 +109,13 @@ pub fn all_dialects() -> TestedDialects {
}
}
pub fn only<T>(v: &[T]) -> &T {
assert_eq!(1, v.len());
v.first().unwrap()
pub fn only<T>(v: impl IntoIterator<Item = T>) -> T {
let mut iter = v.into_iter();
if let (Some(item), None) = (iter.next(), iter.next()) {
item
} else {
panic!("only called on collection without exactly one item")
}
}
pub fn expr_from_projection(item: &SQLSelectItem) -> &ASTNode {