-
Notifications
You must be signed in to change notification settings - Fork 605
Add support for qualified column names in JOIN ... USING #1663
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9342,12 +9342,37 @@ impl<'a> Parser<'a> { | |
optional: IsOptional, | ||
allow_empty: bool, | ||
) -> Result<Vec<Ident>, ParserError> { | ||
self.parse_parenthesized_column_list_inner(optional, allow_empty, |p| p.parse_identifier()) | ||
} | ||
|
||
/// Parses a parenthesized comma-separated list of unqualified, possibly quoted identifiers | ||
pub fn parse_parenthesized_qualified_column_list( | ||
&mut self, | ||
optional: IsOptional, | ||
allow_empty: bool, | ||
) -> Result<Vec<ObjectName>, ParserError> { | ||
self.parse_parenthesized_column_list_inner(optional, allow_empty, |p| { | ||
p.parse_object_name(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the |
||
}) | ||
} | ||
|
||
/// Parses a parenthesized comma-separated list of columns using | ||
/// the provided function to parse each element. | ||
fn parse_parenthesized_column_list_inner<F, T>( | ||
&mut self, | ||
optional: IsOptional, | ||
allow_empty: bool, | ||
mut f: F, | ||
) -> Result<Vec<T>, ParserError> | ||
where | ||
F: FnMut(&mut Parser) -> Result<T, ParserError>, | ||
{ | ||
if self.consume_token(&Token::LParen) { | ||
if allow_empty && self.peek_token().token == Token::RParen { | ||
self.next_token(); | ||
Ok(vec![]) | ||
} else { | ||
let cols = self.parse_comma_separated(|p| p.parse_identifier())?; | ||
let cols = self.parse_comma_separated(|p| f(p))?; | ||
self.expect_token(&Token::RParen)?; | ||
Ok(cols) | ||
} | ||
|
@@ -9358,7 +9383,7 @@ impl<'a> Parser<'a> { | |
} | ||
} | ||
|
||
/// Parse a parenthesized comma-separated list of table alias column definitions. | ||
/// Parses a parenthesized comma-separated list of table alias column definitions. | ||
fn parse_table_alias_column_defs(&mut self) -> Result<Vec<TableAliasColumnDef>, ParserError> { | ||
if self.consume_token(&Token::LParen) { | ||
let cols = self.parse_comma_separated(|p| { | ||
|
@@ -11853,7 +11878,7 @@ impl<'a> Parser<'a> { | |
let constraint = self.parse_expr()?; | ||
Ok(JoinConstraint::On(constraint)) | ||
} else if self.parse_keyword(Keyword::USING) { | ||
let columns = self.parse_parenthesized_column_list(Mandatory, false)?; | ||
let columns = self.parse_parenthesized_qualified_column_list(Mandatory, false)?; | ||
Ok(JoinConstraint::Using(columns)) | ||
} else { | ||
Ok(JoinConstraint::None) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2650,6 +2650,9 @@ fn asof_joins() { | |
"ON s.state = p.state ", | ||
"ORDER BY s.observed", | ||
)); | ||
|
||
// Snowflake allows fully-qualified column names inside USING | ||
snowflake().verified_stmt("SELECT * FROM tbl1 AS t1 JOIN tbl2 AS t2 USING(t2.col1)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can add this scenario to the |
||
} | ||
|
||
#[test] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc comment doesn't seem to match the behavior (unqualified vs qualified)? also it could be nice if the doc highlights that the parenthesis is also expected in the input (maybe with an example)