@@ -10961,7 +10961,10 @@ fn parse_pivot_table() {
1096110961 expected_function("b", Some("t")),
1096210962 expected_function("c", Some("u")),
1096310963 ],
10964- value_column: vec![Ident::new("a"), Ident::new("MONTH")],
10964+ value_column: vec![Expr::CompoundIdentifier(vec![
10965+ Ident::new("a"),
10966+ Ident::new("MONTH")
10967+ ])],
1096510968 value_source: PivotValueSource::List(vec![
1096610969 ExprWithAlias {
1096710970 expr: Expr::value(number("1")),
@@ -11008,6 +11011,75 @@ fn parse_pivot_table() {
1100811011 verified_stmt(sql_without_table_alias).to_string(),
1100911012 sql_without_table_alias
1101011013 );
11014+
11015+ let multiple_value_columns_sql = concat!(
11016+ "SELECT * FROM person ",
11017+ "PIVOT(",
11018+ "SUM(age) AS a, AVG(class) AS c ",
11019+ "FOR (name, age) IN (('John', 30) AS c1, ('Mike', 40) AS c2))",
11020+ );
11021+
11022+ assert_eq!(
11023+ verified_only_select(multiple_value_columns_sql).from[0].relation,
11024+ Pivot {
11025+ table: Box::new(TableFactor::Table {
11026+ name: ObjectName::from(vec![Ident::new("person")]),
11027+ alias: None,
11028+ args: None,
11029+ with_hints: vec![],
11030+ version: None,
11031+ partitions: vec![],
11032+ with_ordinality: false,
11033+ json_path: None,
11034+ sample: None,
11035+ index_hints: vec![],
11036+ }),
11037+ aggregate_functions: vec![
11038+ ExprWithAlias {
11039+ expr: call("SUM", [Expr::Identifier(Ident::new("age"))]),
11040+ alias: Some(Ident::new("a"))
11041+ },
11042+ ExprWithAlias {
11043+ expr: call("AVG", [Expr::Identifier(Ident::new("class"))]),
11044+ alias: Some(Ident::new("c"))
11045+ },
11046+ ],
11047+ value_column: vec![
11048+ Expr::Identifier(Ident::new("name")),
11049+ Expr::Identifier(Ident::new("age")),
11050+ ],
11051+ value_source: PivotValueSource::List(vec![
11052+ ExprWithAlias {
11053+ expr: Expr::Tuple(vec![
11054+ Expr::Value(
11055+ (Value::SingleQuotedString("John".to_string())).with_empty_span()
11056+ ),
11057+ Expr::Value(
11058+ (Value::Number("30".parse().unwrap(), false)).with_empty_span()
11059+ ),
11060+ ]),
11061+ alias: Some(Ident::new("c1"))
11062+ },
11063+ ExprWithAlias {
11064+ expr: Expr::Tuple(vec![
11065+ Expr::Value(
11066+ (Value::SingleQuotedString("Mike".to_string())).with_empty_span()
11067+ ),
11068+ Expr::Value(
11069+ (Value::Number("40".parse().unwrap(), false)).with_empty_span()
11070+ ),
11071+ ]),
11072+ alias: Some(Ident::new("c2"))
11073+ },
11074+ ]),
11075+ default_on_null: None,
11076+ alias: None,
11077+ }
11078+ );
11079+ assert_eq!(
11080+ verified_stmt(multiple_value_columns_sql).to_string(),
11081+ multiple_value_columns_sql
11082+ );
1101111083}
1101211084
1101311085#[test]
@@ -11340,7 +11412,7 @@ fn parse_pivot_unpivot_table() {
1134011412 expr: call("sum", [Expr::Identifier(Ident::new("population"))]),
1134111413 alias: None
1134211414 }],
11343- value_column: vec![Ident::new("year")],
11415+ value_column: vec![Expr::Identifier( Ident::new("year") )],
1134411416 value_source: PivotValueSource::List(vec![
1134511417 ExprWithAlias {
1134611418 expr: Expr::Value(
0 commit comments