-
Notifications
You must be signed in to change notification settings - Fork 627
feat: support multi value column unpivot & alias 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
base: main
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
|
@@ -10947,11 +10947,11 @@ fn parse_unpivot_table() { | |
index_hints: vec![], | ||
}), | ||
null_inclusion: None, | ||
value: Ident { | ||
value: vec![Ident { | ||
value: "quantity".to_string(), | ||
quote_style: None, | ||
span: Span::empty(), | ||
}, | ||
}], | ||
|
||
name: Ident { | ||
value: "quarter".to_string(), | ||
|
@@ -10960,7 +10960,7 @@ fn parse_unpivot_table() { | |
}, | ||
columns: ["Q1", "Q2", "Q3", "Q4"] | ||
.into_iter() | ||
.map(Ident::new) | ||
.map(|col| IdentsWithAlias::new(vec![Ident::new(col)], None)) | ||
.collect(), | ||
alias: Some(TableAlias { | ||
name: Ident::new("u"), | ||
|
@@ -11022,6 +11022,67 @@ fn parse_unpivot_table() { | |
verified_stmt(sql_unpivot_include_nulls).to_string(), | ||
sql_unpivot_include_nulls | ||
); | ||
|
||
let sql_unpivot_with_alias = concat!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chenkovsky do you know or would you be able to check if this feature is supported by any of the dialects that the parser currently supports? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comes from spark. |
||
"SELECT * FROM sales AS s ", | ||
"UNPIVOT INCLUDE NULLS (quantity FOR quarter IN (Q1 AS Quater1, Q2 AS Quater2, Q3 AS Quater3, Q4 AS Quater4)) AS u (product, quarter, quantity)" | ||
); | ||
|
||
if let Unpivot { value, columns, .. } = | ||
&verified_only_select(sql_unpivot_with_alias).from[0].relation | ||
{ | ||
assert_eq!( | ||
*columns, | ||
vec![ | ||
IdentsWithAlias::new(vec![Ident::new("Q1")], Some(Ident::new("Quater1"))), | ||
IdentsWithAlias::new(vec![Ident::new("Q2")], Some(Ident::new("Quater2"))), | ||
IdentsWithAlias::new(vec![Ident::new("Q3")], Some(Ident::new("Quater3"))), | ||
IdentsWithAlias::new(vec![Ident::new("Q4")], Some(Ident::new("Quater4"))), | ||
] | ||
); | ||
assert_eq!(*value, vec![Ident::new("quantity")]); | ||
} | ||
|
||
assert_eq!( | ||
verified_stmt(sql_unpivot_with_alias).to_string(), | ||
sql_unpivot_with_alias | ||
); | ||
|
||
let sql_unpivot_with_alias = concat!( | ||
"SELECT * FROM sales AS s ", | ||
"UNPIVOT INCLUDE NULLS ((first_quarter, second_quarter) ", | ||
"FOR half_of_the_year IN (", | ||
"(Q1, Q2) AS H1, ", | ||
"(Q3, Q4) AS H2", | ||
"))" | ||
); | ||
|
||
if let Unpivot { value, columns, .. } = | ||
&verified_only_select(sql_unpivot_with_alias).from[0].relation | ||
{ | ||
assert_eq!( | ||
*columns, | ||
vec![ | ||
IdentsWithAlias::new( | ||
vec![Ident::new("Q1"), Ident::new("Q2")], | ||
Some(Ident::new("H1")) | ||
), | ||
IdentsWithAlias::new( | ||
vec![Ident::new("Q3"), Ident::new("Q4")], | ||
Some(Ident::new("H2")) | ||
), | ||
] | ||
); | ||
assert_eq!( | ||
*value, | ||
vec![Ident::new("first_quarter"), Ident::new("second_quarter")] | ||
); | ||
} | ||
|
||
assert_eq!( | ||
verified_stmt(sql_unpivot_with_alias).to_string(), | ||
sql_unpivot_with_alias | ||
); | ||
} | ||
|
||
#[test] | ||
|
@@ -11119,11 +11180,11 @@ fn parse_pivot_unpivot_table() { | |
index_hints: vec![], | ||
}), | ||
null_inclusion: None, | ||
value: Ident { | ||
value: vec![Ident { | ||
value: "population".to_string(), | ||
quote_style: None, | ||
span: Span::empty() | ||
}, | ||
}], | ||
|
||
name: Ident { | ||
value: "year".to_string(), | ||
|
@@ -11132,7 +11193,7 @@ fn parse_pivot_unpivot_table() { | |
}, | ||
columns: ["population_2000", "population_2010"] | ||
.into_iter() | ||
.map(Ident::new) | ||
.map(|col| IdentsWithAlias::new(vec![Ident::new(col)], None)) | ||
.collect(), | ||
alias: Some(TableAlias { | ||
name: Ident::new("u"), | ||
|
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.
should we use expr::Identifier ? otherwise we cannot visit this ident by vistor.