@@ -10925,6 +10925,71 @@ fn parse_pivot_table() {
1092510925 verified_stmt(sql_without_table_alias).to_string(),
1092610926 sql_without_table_alias
1092710927 );
10928+
10929+ let multiple_value_columns_sql = concat!(
10930+ "SELECT * FROM person ",
10931+ "PIVOT(",
10932+ "SUM(age) AS a, AVG(class) AS c ",
10933+ "FOR (name, age) IN (('John', 30) AS c1, ('Mike', 40) AS c2))",
10934+ );
10935+
10936+ assert_eq!(
10937+ verified_only_select(multiple_value_columns_sql).from[0].relation,
10938+ Pivot {
10939+ table: Box::new(TableFactor::Table {
10940+ name: ObjectName::from(vec![Ident::new("person")]),
10941+ alias: None,
10942+ args: None,
10943+ with_hints: vec![],
10944+ version: None,
10945+ partitions: vec![],
10946+ with_ordinality: false,
10947+ json_path: None,
10948+ sample: None,
10949+ index_hints: vec![],
10950+ }),
10951+ aggregate_functions: vec![
10952+ ExprWithAlias {
10953+ expr: call("SUM", [Expr::Identifier(Ident::new("age"))]),
10954+ alias: Some(Ident::new("a"))
10955+ },
10956+ ExprWithAlias {
10957+ expr: call("AVG", [Expr::Identifier(Ident::new("class"))]),
10958+ alias: Some(Ident::new("c"))
10959+ },
10960+ ],
10961+ value_column: vec![
10962+ Expr::Identifier(Ident::new("name")),
10963+ Expr::Identifier(Ident::new("age")),
10964+ ],
10965+ value_source: PivotValueSource::List(vec![
10966+ ExprWithAlias {
10967+ expr: Expr::Tuple(vec![
10968+ Expr::Value(
10969+ (Value::SingleQuotedString("John".to_string())).with_empty_span()
10970+ ),
10971+ Expr::Value((Value::Number("30".into(), false)).with_empty_span()),
10972+ ]),
10973+ alias: Some(Ident::new("c1"))
10974+ },
10975+ ExprWithAlias {
10976+ expr: Expr::Tuple(vec![
10977+ Expr::Value(
10978+ (Value::SingleQuotedString("Mike".to_string())).with_empty_span()
10979+ ),
10980+ Expr::Value((Value::Number("40".into(), false)).with_empty_span()),
10981+ ]),
10982+ alias: Some(Ident::new("c2"))
10983+ },
10984+ ]),
10985+ default_on_null: None,
10986+ alias: None,
10987+ }
10988+ );
10989+ assert_eq!(
10990+ verified_stmt(multiple_value_columns_sql).to_string(),
10991+ multiple_value_columns_sql
10992+ );
1092810993}
1092910994
1093010995#[test]
@@ -11146,7 +11211,7 @@ fn parse_pivot_unpivot_table() {
1114611211 expr: call("sum", [Expr::Identifier(Ident::new("population"))]),
1114711212 alias: None
1114811213 }],
11149- value_column: vec![Expr::CompoundIdentifier(vec![ Ident::new("year")] )],
11214+ value_column: vec![Expr::Identifier( Ident::new("year"))],
1115011215 value_source: PivotValueSource::List(vec![
1115111216 ExprWithAlias {
1115211217 expr: Expr::Value(
0 commit comments