-
Notifications
You must be signed in to change notification settings - Fork 665
feat: support multi value columns and aliases in unpivot #1969
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 3 commits
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 |
---|---|---|
|
@@ -10810,6 +10810,16 @@ impl<'a> Parser<'a> { | |
} | ||
} | ||
|
||
pub fn parse_parenthesized_columns_with_alias_list( | ||
&mut self, | ||
optional: IsOptional, | ||
allow_empty: bool, | ||
) -> Result<Vec<ExprWithAlias>, ParserError> { | ||
self.parse_parenthesized_column_list_inner(optional, allow_empty, |p| { | ||
p.parse_expr_with_alias() | ||
}) | ||
|
||
} | ||
|
||
/// Parses a parenthesized comma-separated list of unqualified, possibly quoted identifiers. | ||
/// For example: `(col1, "col 2", ...)` | ||
pub fn parse_parenthesized_column_list( | ||
|
@@ -13882,11 +13892,25 @@ impl<'a> Parser<'a> { | |
None | ||
}; | ||
self.expect_token(&Token::LParen)?; | ||
let value = self.parse_identifier()?; | ||
let value = match self.peek_token_ref().token { | ||
Token::LParen => { | ||
// multi value column unpivot | ||
Expr::Tuple( | ||
self.parse_parenthesized_column_list(Mandatory, false)? | ||
.into_iter() | ||
.map(Expr::Identifier) | ||
.collect(), | ||
) | ||
} | ||
_ => { | ||
// single value column unpivot | ||
Expr::Identifier(self.parse_identifier()?) | ||
} | ||
|
||
}; | ||
self.expect_keyword_is(Keyword::FOR)?; | ||
let name = self.parse_identifier()?; | ||
self.expect_keyword_is(Keyword::IN)?; | ||
let columns = self.parse_parenthesized_column_list(Mandatory, false)?; | ||
let columns = self.parse_parenthesized_columns_with_alias_list(Mandatory, false)?; | ||
self.expect_token(&Token::RParen)?; | ||
let alias = self.maybe_parse_table_alias()?; | ||
Ok(TableFactor::Unpivot { | ||
|
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.
Can we include the link to the databricks documentation here as well?