iffyio commented on code in PR #1970:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/1970#discussion_r2249139287
##########
src/parser/mod.rs:
##########
@@ -13828,7 +13840,13 @@ impl<'a> Parser<'a> {
self.expect_token(&Token::LParen)?;
let aggregate_functions =
self.parse_comma_separated(Self::parse_aliased_function_call)?;
self.expect_keyword_is(Keyword::FOR)?;
- let value_column = self.parse_period_separated(|p|
p.parse_identifier())?;
+ let value_column = if self.peek_token_ref().token == Token::LParen {
+ self.parse_parenthesized_compound_identifier_list(Mandatory,
false)?
+ } else {
+ vec![Expr::CompoundIdentifier(
+ self.parse_period_separated(|p| p.parse_identifier())?,
+ )]
+ };
Review Comment:
similar to unpivot can we call parse_expr directly here?
##########
tests/sqlparser_common.rs:
##########
@@ -10922,6 +10925,15 @@ fn parse_pivot_table() {
verified_stmt(sql_without_table_alias).to_string(),
sql_without_table_alias
);
+
+ let sql_with_multiple_value_column = concat!(
+ "SELECT * FROM person ",
+ "PIVOT(SUM(age) AS a, AVG(class) AS c FOR (name, age) IN (('John', 30)
AS c1, ('Mike', 40) AS c2))"
+ );
+ assert_eq!(
+ verified_stmt(sql_with_multiple_value_column).to_string(),
+ sql_with_multiple_value_column
+ );
Review Comment:
hmm this assertion is probably not needed, I think verified_stmt already
does the same assertion
##########
src/ast/query.rs:
##########
@@ -1336,7 +1336,7 @@ pub enum TableFactor {
Pivot {
table: Box<TableFactor>,
aggregate_functions: Vec<ExprWithAlias>, // Function expression
- value_column: Vec<Ident>,
+ value_column: Vec<Expr>, // Expr is a identifier or a
compound identifier
Review Comment:
```suggestion
value_column: Vec<Expr>,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]