-
Notifications
You must be signed in to change notification settings - Fork 605
support PIVOT table syntax #836
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
Conversation
Pull Request Test Coverage Report for Build 4466498674
💛 - Coveralls |
Failing lint should be resolved within #835 |
@@ -670,6 +670,17 @@ pub enum TableFactor { | |||
table_with_joins: Box<TableWithJoins>, | |||
alias: Option<TableAlias>, | |||
}, | |||
/// Represents PIVOT operation on a table. | |||
/// For example `FROM monthly_sales PIVOT(sum(amount) FOR MONTH IN ('JAN', 'FEB'))` |
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.
Could you add a link to the Snowflake docs (https://docs.snowflake.com/en/sql-reference/constructs/pivot) in here?
#[test] | ||
fn parse_pivot_table() { | ||
let sql = concat!( | ||
"SELECT * FROM monthly_sales AS a ", |
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.
- can you add a test case without the
AS
component? - can you add a roundtrip test (so we can verify the
Display()
implementation works too)
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.
- There is below a variable
sql_without_table_alias
that tests this. - Will add the roundtrip as it is missing.
src/parser.rs
Outdated
self.expect_token(&Token::LParen)?; | ||
let function_name = match self.next_token().token { | ||
Token::Word(w) => Ok(w.value), | ||
_ => self.expected("a function name", self.peek_token()), |
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.
maybe "an aggregate function" in the error message?
src/parser.rs
Outdated
}?; | ||
let function = self | ||
.parse_function(ObjectName(vec![Ident::new(function_name)])) | ||
.unwrap(); |
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.
shouldn't we propagate the error here instead of unwrapping?
src/parser.rs
Outdated
.parse_function(ObjectName(vec![Ident::new(function_name)])) | ||
.unwrap(); | ||
self.expect_keyword(Keyword::FOR)?; | ||
let mut value_column = vec![self.parse_identifier()?]; |
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.
why not use self.parse_object_name()
?
Signed-off-by: Pawel Leszczynski <[email protected]>
0fcafd9
to
883c7c0
Compare
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.
Thank you @pawel-big-lebowski -- looks good to me. Thanks for the assist @ankrgyl
PIVOT TABLE
syntax is available in Snowflake.This PR introduces
PIVOT
support within sqlparser-rs.