Skip to content

Snowflake: support nested join without parentheses #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11695,6 +11695,11 @@ impl<'a> Parser<'a> {
// Note that for keywords to be properly handled here, they need to be
// added to `RESERVED_FOR_TABLE_ALIAS`, otherwise they may be parsed as
// a table alias.
let joins = self.parse_joins()?;
Ok(TableWithJoins { relation, joins })
}

fn parse_joins(&mut self) -> Result<Vec<Join>, ParserError> {
let mut joins = vec![];
loop {
let global = self.parse_keyword(Keyword::GLOBAL);
Expand Down Expand Up @@ -11823,7 +11828,16 @@ impl<'a> Parser<'a> {
}
_ => break,
};
let relation = self.parse_table_factor()?;
let mut relation = self.parse_table_factor()?;

if self.peek_parens_less_nested_join() {
let joins = self.parse_joins()?;
relation = TableFactor::NestedJoin {
table_with_joins: Box::new(TableWithJoins { relation, joins }),
alias: None,
};
}

let join_constraint = self.parse_join_constraint(natural)?;
Join {
relation,
Expand All @@ -11833,7 +11847,21 @@ impl<'a> Parser<'a> {
};
joins.push(join);
}
Ok(TableWithJoins { relation, joins })
Ok(joins)
}

fn peek_parens_less_nested_join(&self) -> bool {
matches!(
self.peek_token_ref().token,
Token::Word(Word {
keyword: Keyword::JOIN
| Keyword::INNER
| Keyword::LEFT
| Keyword::RIGHT
| Keyword::FULL,
..
})
)
}

/// A table name or a parenthesized subquery, followed by optional `[AS] alias`
Expand Down
Loading