Support for (+) outer join syntax (#1145)

This commit is contained in:
Joey Hain 2024-02-28 14:27:42 -08:00 committed by GitHub
parent b284fdfb7e
commit 6a9b6f547d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 111 additions and 2 deletions

View file

@ -998,8 +998,19 @@ impl<'a> Parser<'a> {
if ends_with_wildcard {
Ok(Expr::QualifiedWildcard(ObjectName(id_parts)))
} else if self.consume_token(&Token::LParen) {
self.prev_token();
self.parse_function(ObjectName(id_parts))
if dialect_of!(self is SnowflakeDialect | MsSqlDialect)
&& self.consume_tokens(&[Token::Plus, Token::RParen])
{
Ok(Expr::OuterJoin(Box::new(
match <[Ident; 1]>::try_from(id_parts) {
Ok([ident]) => Expr::Identifier(ident),
Err(parts) => Expr::CompoundIdentifier(parts),
},
)))
} else {
self.prev_token();
self.parse_function(ObjectName(id_parts))
}
} else {
Ok(Expr::CompoundIdentifier(id_parts))
}
@ -2860,6 +2871,21 @@ impl<'a> Parser<'a> {
}
}
/// If the current and subsequent tokens exactly match the `tokens`
/// sequence, consume them and returns true. Otherwise, no tokens are
/// consumed and returns false
#[must_use]
pub fn consume_tokens(&mut self, tokens: &[Token]) -> bool {
let index = self.index;
for token in tokens {
if !self.consume_token(token) {
self.index = index;
return false;
}
}
true
}
/// Bail out if the current token is not an expected keyword, or consume it if it is
pub fn expect_token(&mut self, expected: &Token) -> Result<(), ParserError> {
if self.consume_token(expected) {