mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-19 05:30:19 +00:00
Support NestedJoin
with an alias (#551)
* add alias for nestedjoin * fmt * add/modify test cases * inline nestedjoin instead of macro
This commit is contained in:
parent
e24951e080
commit
076b587bb2
5 changed files with 91 additions and 37 deletions
|
@ -3869,12 +3869,24 @@ impl<'a> Parser<'a> {
|
|||
#[allow(clippy::if_same_then_else)]
|
||||
if !table_and_joins.joins.is_empty() {
|
||||
self.expect_token(&Token::RParen)?;
|
||||
Ok(TableFactor::NestedJoin(Box::new(table_and_joins))) // (A)
|
||||
} else if let TableFactor::NestedJoin(_) = &table_and_joins.relation {
|
||||
let alias = self.parse_optional_table_alias(keywords::RESERVED_FOR_TABLE_ALIAS)?;
|
||||
Ok(TableFactor::NestedJoin {
|
||||
table_with_joins: Box::new(table_and_joins),
|
||||
alias,
|
||||
}) // (A)
|
||||
} else if let TableFactor::NestedJoin {
|
||||
table_with_joins: _,
|
||||
alias: _,
|
||||
} = &table_and_joins.relation
|
||||
{
|
||||
// (B): `table_and_joins` (what we found inside the parentheses)
|
||||
// is a nested join `(foo JOIN bar)`, not followed by other joins.
|
||||
self.expect_token(&Token::RParen)?;
|
||||
Ok(TableFactor::NestedJoin(Box::new(table_and_joins)))
|
||||
let alias = self.parse_optional_table_alias(keywords::RESERVED_FOR_TABLE_ALIAS)?;
|
||||
Ok(TableFactor::NestedJoin {
|
||||
table_with_joins: Box::new(table_and_joins),
|
||||
alias,
|
||||
})
|
||||
} else if dialect_of!(self is SnowflakeDialect | GenericDialect) {
|
||||
// Dialect-specific behavior: Snowflake diverges from the
|
||||
// standard and from most of the other implementations by
|
||||
|
@ -3893,7 +3905,8 @@ impl<'a> Parser<'a> {
|
|||
TableFactor::Derived { alias, .. }
|
||||
| TableFactor::Table { alias, .. }
|
||||
| TableFactor::UNNEST { alias, .. }
|
||||
| TableFactor::TableFunction { alias, .. } => {
|
||||
| TableFactor::TableFunction { alias, .. }
|
||||
| TableFactor::NestedJoin { alias, .. } => {
|
||||
// but not `FROM (mytable AS alias1) AS alias2`.
|
||||
if let Some(inner_alias) = alias {
|
||||
return Err(ParserError::ParserError(format!(
|
||||
|
@ -3906,7 +3919,6 @@ impl<'a> Parser<'a> {
|
|||
// `(mytable AS alias)`
|
||||
alias.replace(outer_alias);
|
||||
}
|
||||
TableFactor::NestedJoin(_) => unreachable!(),
|
||||
};
|
||||
}
|
||||
// Do not store the extra set of parens in the AST
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue