-
Notifications
You must be signed in to change notification settings - Fork 602
Add suppport for Show Objects statement for the Snowflake parser #1702
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
Add suppport for Show Objects statement for the Snowflake parser #1702
Conversation
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.
Thanks @DanCodedThis! Left some comments
src/ast/mod.rs
Outdated
terse: bool, | ||
show_options: ShowStatementOptions, |
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 we use a struct to wrap the arguments? we're currently trying to move away from the anonymous struct pattern (#1204)
Something like
struct ShowObjects {
terse: bool,
show_options: ShowStatementOptions,
}
Statement::ShowObjects(ShowObjects)
src/ast/mod.rs
Outdated
/// [ IN | ||
/// { | ||
/// ACCOUNT | | ||
/// | ||
/// DATABASE | | ||
/// DATABASE <database_name> | | ||
/// | ||
/// SCHEMA | | ||
/// SCHEMA <schema_name> | | ||
/// <schema_name> | ||
/// | ||
/// APPLICATION <application_name> | | ||
/// APPLICATION PACKAGE <application_package_name> | | ||
/// } | ||
/// ] | ||
/// [ STARTS WITH '<name_string>' ] | ||
/// [ LIMIT <rows> [ FROM '<name_string>' ] ] | ||
/// ``` |
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.
Thinking since this is quite verbose we can either leave it out, relying on the link to the documentation and a description or we can use a shorter summary of the syntax like an example sql statement?
src/dialect/snowflake.rs
Outdated
if parser.parse_keyword(Keyword::OBJECTS) { | ||
return Some(parse_show_objects(terse, parser)); | ||
} else { | ||
return Some(parser.parse_show()); |
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.
what would be the behavior if terse
is true here, can we maybe include a test case demonstrating that scenario?
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.
Originally there was no else branch, but there was a bug in my code, which was fixed like this (maybe this is too hacky?). The bug wasn't found or fixed by me. But for example, before the else branch: when we got DATABASES
instead of OBJECTS
we got an error in other tests.
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.
I think I fixed this the right way, shouldn't need tests now.
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.
Added the terse
test in other relevant snowflake SHOW
statement tests, just in case (checked, they all worked and the ShowObjects
also)
@@ -2975,6 +2975,25 @@ fn test_parse_show_schemas() { | |||
snowflake().verified_stmt("SHOW SCHEMAS IN DATABASE STARTS WITH 'abc' LIMIT 20 FROM 'xyz'"); | |||
} | |||
|
|||
#[test] | |||
fn test_parse_show_objects() { | |||
snowflake().verified_stmt("SHOW OBJECTS"); |
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.
Since this introduces a new node in the AST, can we add an assertion for one of these test cases covering that the AST looks like what is expected? i.e a test in this syle
As suggested Co-authored-by: Ifeanyi Ubah <[email protected]>
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.
LGTM! Thanks @DanCodedThis!
cc @alamb
…che#1702) Co-authored-by: Denys Tsomenko <[email protected]> Co-authored-by: Ifeanyi Ubah <[email protected]>
It's a naive implementation, since
ShowStatementOptions
allow for cases that are not supported by SnowflakeSHOW OBJECTS
like:SHOW TERSE OBJECTS WHERE ... ...
SHOW TERSE OBJECTS LIKE '%test%' ...
Snowflake spec: https://docs.snowflake.com/en/sql-reference/sql/show-objects