Skip to content

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

Merged
merged 14 commits into from
Feb 6, 2025

Conversation

DanCodedThis
Copy link
Contributor

It's a naive implementation, since ShowStatementOptions allow for cases that are not supported by Snowflake SHOW OBJECTS like:

  • SHOW TERSE OBJECTS WHERE ... ...
  • Instead of SHOW TERSE OBJECTS LIKE '%test%' ...

Snowflake spec: https://docs.snowflake.com/en/sql-reference/sql/show-objects

Copy link
Contributor

@iffyio iffyio left a 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
Comment on lines 3005 to 3006
terse: bool,
show_options: ShowStatementOptions,
Copy link
Contributor

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
Comment on lines 2984 to 3001
/// [ 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>' ] ]
/// ```
Copy link
Contributor

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?

if parser.parse_keyword(Keyword::OBJECTS) {
return Some(parse_show_objects(terse, parser));
} else {
return Some(parser.parse_show());
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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");
Copy link
Contributor

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

@DanCodedThis DanCodedThis requested a review from iffyio February 6, 2025 13:03
Copy link
Contributor

@iffyio iffyio left a 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

@iffyio iffyio merged commit 0b8ba91 into apache:main Feb 6, 2025
9 checks passed
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants