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

@ -19,8 +19,8 @@ fn parse_mssql_identifiers() {
expr_from_projection(&select.projection[1]),
);
assert_eq!(2, select.projection.len());
match select.relation {
Some(TableFactor::Table { name, .. }) => {
match &only(&select.from).relation {
TableFactor::Table { name, .. } => {
assert_eq!("##temp".to_string(), name.to_string());
}
_ => unreachable!(),