mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-23 07:24:10 +00:00
Update comments (follow-up to PR #155)
https://github.com/andygrove/sqlparser-rs/pull/155
This commit is contained in:
parent
33303b244f
commit
05a29212ff
2 changed files with 16 additions and 19 deletions
|
@ -225,10 +225,11 @@ pub enum TableFactor {
|
||||||
subquery: Box<Query>,
|
subquery: Box<Query>,
|
||||||
alias: Option<TableAlias>,
|
alias: Option<TableAlias>,
|
||||||
},
|
},
|
||||||
/// Represents a parenthesized join expression, such as
|
/// Represents a parenthesized table factor. The SQL spec only allows a
|
||||||
/// `(foo <JOIN> bar [ <JOIN> baz ... ])`.
|
/// join expression (`(foo <JOIN> bar [ <JOIN> baz ... ])`) to be nested,
|
||||||
/// The inner `TableWithJoins` can have no joins only if its
|
/// possibly several times, but the parser also accepts the non-standard
|
||||||
/// `relation` is itself a `TableFactor::NestedJoin`.
|
/// nesting of bare tables (`table_with_joins.joins.is_empty()`), so the
|
||||||
|
/// name `NestedJoin` is a bit of misnomer.
|
||||||
NestedJoin(Box<TableWithJoins>),
|
NestedJoin(Box<TableWithJoins>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1771,7 +1771,6 @@ impl Parser {
|
||||||
// ^ ^ ^ ^
|
// ^ ^ ^ ^
|
||||||
// | | | |
|
// | | | |
|
||||||
// | | | |
|
// | | | |
|
||||||
// | | | |
|
|
||||||
// | | | (4) belongs to a SetExpr::Query inside the subquery
|
// | | | (4) belongs to a SetExpr::Query inside the subquery
|
||||||
// | | (3) starts a derived table (subquery)
|
// | | (3) starts a derived table (subquery)
|
||||||
// | (2) starts a nested join
|
// | (2) starts a nested join
|
||||||
|
@ -1784,23 +1783,20 @@ impl Parser {
|
||||||
// case (3), and the next token would be `NATURAL`.
|
// case (3), and the next token would be `NATURAL`.
|
||||||
Ok(table_factor) => Ok(table_factor),
|
Ok(table_factor) => Ok(table_factor),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// The '(' we've recently consumed does not start a derived
|
// A parsing error from `parse_derived_table_factor` indicates that
|
||||||
// table. For valid input this can happen either when the
|
// the '(' we've recently consumed does not start a derived table
|
||||||
// token following the paren can't start a query (e.g. `foo`
|
// (cases 1, 2, or 4). Ignore the error and back up to where we
|
||||||
// in `FROM (foo NATURAL JOIN bar)`, or when the '(' we've
|
// were before - right after the opening '('.
|
||||||
// consumed is followed by another '(' that starts a
|
|
||||||
// derived table, like (3), or another nested join (2).
|
|
||||||
//
|
|
||||||
// Ignore the error and back up to where we were before.
|
|
||||||
// Either we'll be able to parse a valid nested join, or
|
|
||||||
// we won't, and we'll return that error instead.
|
|
||||||
//
|
|
||||||
// Even the SQL spec prohibits derived tables and bare
|
|
||||||
// tables from appearing alone in parentheses, we allowed it
|
|
||||||
// as some Db's allowed that (snowflake as example)
|
|
||||||
self.index = index;
|
self.index = index;
|
||||||
|
|
||||||
|
// Inside the parentheses we expect to find a table factor
|
||||||
|
// followed by some joins or another level of nesting.
|
||||||
let table_and_joins = self.parse_table_and_joins()?;
|
let table_and_joins = self.parse_table_and_joins()?;
|
||||||
self.expect_token(&Token::RParen)?;
|
self.expect_token(&Token::RParen)?;
|
||||||
|
// The SQL spec prohibits derived and bare tables from appearing
|
||||||
|
// alone in parentheses. We don't enforce this as some databases
|
||||||
|
// (e.g. Snowflake) allow such syntax.
|
||||||
|
|
||||||
Ok(TableFactor::NestedJoin(Box::new(table_and_joins)))
|
Ok(TableFactor::NestedJoin(Box::new(table_and_joins)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue