@@ -10964,7 +10964,10 @@ fn parse_pivot_table() {
1096410964 expected_function("b", Some("t")),
1096510965 expected_function("c", Some("u")),
1096610966 ],
10967- value_column: vec![Ident::new("a"), Ident::new("MONTH")],
10967+ value_column: vec![Expr::CompoundIdentifier(vec![
10968+ Ident::new("a"),
10969+ Ident::new("MONTH")
10970+ ])],
1096810971 value_source: PivotValueSource::List(vec![
1096910972 ExprWithAlias {
1097010973 expr: Expr::value(number("1")),
@@ -11011,6 +11014,75 @@ fn parse_pivot_table() {
1101111014 verified_stmt(sql_without_table_alias).to_string(),
1101211015 sql_without_table_alias
1101311016 );
11017+
11018+ let multiple_value_columns_sql = concat!(
11019+ "SELECT * FROM person ",
11020+ "PIVOT(",
11021+ "SUM(age) AS a, AVG(class) AS c ",
11022+ "FOR (name, age) IN (('John', 30) AS c1, ('Mike', 40) AS c2))",
11023+ );
11024+
11025+ assert_eq!(
11026+ verified_only_select(multiple_value_columns_sql).from[0].relation,
11027+ Pivot {
11028+ table: Box::new(TableFactor::Table {
11029+ name: ObjectName::from(vec![Ident::new("person")]),
11030+ alias: None,
11031+ args: None,
11032+ with_hints: vec![],
11033+ version: None,
11034+ partitions: vec![],
11035+ with_ordinality: false,
11036+ json_path: None,
11037+ sample: None,
11038+ index_hints: vec![],
11039+ }),
11040+ aggregate_functions: vec![
11041+ ExprWithAlias {
11042+ expr: call("SUM", [Expr::Identifier(Ident::new("age"))]),
11043+ alias: Some(Ident::new("a"))
11044+ },
11045+ ExprWithAlias {
11046+ expr: call("AVG", [Expr::Identifier(Ident::new("class"))]),
11047+ alias: Some(Ident::new("c"))
11048+ },
11049+ ],
11050+ value_column: vec![
11051+ Expr::Identifier(Ident::new("name")),
11052+ Expr::Identifier(Ident::new("age")),
11053+ ],
11054+ value_source: PivotValueSource::List(vec![
11055+ ExprWithAlias {
11056+ expr: Expr::Tuple(vec![
11057+ Expr::Value(
11058+ (Value::SingleQuotedString("John".to_string())).with_empty_span()
11059+ ),
11060+ Expr::Value(
11061+ (Value::Number("30".parse().unwrap(), false)).with_empty_span()
11062+ ),
11063+ ]),
11064+ alias: Some(Ident::new("c1"))
11065+ },
11066+ ExprWithAlias {
11067+ expr: Expr::Tuple(vec![
11068+ Expr::Value(
11069+ (Value::SingleQuotedString("Mike".to_string())).with_empty_span()
11070+ ),
11071+ Expr::Value(
11072+ (Value::Number("40".parse().unwrap(), false)).with_empty_span()
11073+ ),
11074+ ]),
11075+ alias: Some(Ident::new("c2"))
11076+ },
11077+ ]),
11078+ default_on_null: None,
11079+ alias: None,
11080+ }
11081+ );
11082+ assert_eq!(
11083+ verified_stmt(multiple_value_columns_sql).to_string(),
11084+ multiple_value_columns_sql
11085+ );
1101411086}
1101511087
1101611088#[test]
@@ -11343,7 +11415,7 @@ fn parse_pivot_unpivot_table() {
1134311415 expr: call("sum", [Expr::Identifier(Ident::new("population"))]),
1134411416 alias: None
1134511417 }],
11346- value_column: vec![Ident::new("year")],
11418+ value_column: vec![Expr::Identifier( Ident::new("year") )],
1134711419 value_source: PivotValueSource::List(vec![
1134811420 ExprWithAlias {
1134911421 expr: Expr::Value(
0 commit comments