-
Notifications
You must be signed in to change notification settings - Fork 665
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
Changes from 6 commits
8083bd2
1d71037
e745fb2
c0f4f3c
01615ef
e13a1b8
7768f6f
dd4d972
0a4fcd2
0903a27
bb86d89
b7bcc3b
1812ace
6f562d8
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 |
|---|---|---|
|
|
@@ -2980,6 +2980,32 @@ pub enum Statement { | |
| show_options: ShowStatementOptions, | ||
| }, | ||
| /// ```sql | ||
| /// SHOW [ TERSE ] OBJECTS [ LIKE '<pattern>' ] | ||
| /// [ 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>' ] ] | ||
| /// ``` | ||
| /// Snowflake-specific statement | ||
| /// <https://docs.snowflake.com/en/sql-reference/sql/show-objects> | ||
| ShowObjects { | ||
| terse: bool, | ||
| show_options: ShowStatementOptions, | ||
|
||
| }, | ||
| /// ```sql | ||
| /// SHOW TABLES | ||
| /// ``` | ||
| ShowTables { | ||
|
|
@@ -4642,6 +4668,17 @@ impl fmt::Display for Statement { | |
| )?; | ||
| Ok(()) | ||
| } | ||
| Statement::ShowObjects { | ||
| terse, | ||
| show_options, | ||
| } => { | ||
| write!( | ||
| f, | ||
| "SHOW {terse}OBJECTS{show_options}", | ||
| terse = if *terse { "TERSE " } else { "" }, | ||
| )?; | ||
| Ok(()) | ||
| } | ||
| Statement::ShowTables { | ||
| terse, | ||
| history, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,10 @@ use crate::ast::helpers::stmt_data_loading::{ | |
| StageLoadSelectItem, StageParamsObject, | ||
| }; | ||
| use crate::ast::{ | ||
| ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident, IdentityParameters, IdentityProperty, | ||
| IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, ObjectName, | ||
| RowAccessPolicy, Statement, TagsColumnOption, WrappedCollection, | ||
| ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident, | ||
| IdentityParameters, IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind, | ||
| IdentityPropertyOrder, ObjectName, RowAccessPolicy, Statement, TagsColumnOption, | ||
| WrappedCollection, | ||
| }; | ||
| use crate::dialect::{Dialect, Precedence}; | ||
| use crate::keywords::Keyword; | ||
|
|
@@ -182,6 +183,15 @@ impl Dialect for SnowflakeDialect { | |
| return Some(parse_file_staging_command(kw, parser)); | ||
| } | ||
|
|
||
| if parser.parse_keyword(Keyword::SHOW) { | ||
| let terse = parser.parse_keyword(Keyword::TERSE); | ||
| if parser.parse_keyword(Keyword::OBJECTS) { | ||
| return Some(parse_show_objects(terse, parser)); | ||
| } else { | ||
| return Some(parser.parse_show()); | ||
|
||
| } | ||
| } | ||
|
|
||
| None | ||
| } | ||
|
|
||
|
|
@@ -1054,3 +1064,13 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result<TagsColumnOption | |
|
|
||
| Ok(TagsColumnOption { with, tags }) | ||
| } | ||
|
|
||
| /// Parse snowflake show objects. | ||
| /// <https://docs.snowflake.com/en/sql-reference/sql/show-objects> | ||
| fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result<Statement, ParserError> { | ||
| let show_options = parser.parse_show_stmt_options()?; | ||
| Ok(Statement::ShowObjects { | ||
| terse, | ||
| show_options, | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -586,6 +586,7 @@ define_keywords!( | |
| NUMERIC, | ||
| NVARCHAR, | ||
| OBJECT, | ||
| OBJECTS, | ||
| OCCURRENCES_REGEX, | ||
| OCTETS, | ||
| OCTET_LENGTH, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 commentThe 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 |
||
| snowflake().verified_stmt("SHOW OBJECTS IN abc"); | ||
| snowflake().verified_stmt("SHOW OBJECTS LIKE '%test%' IN abc"); | ||
| snowflake().verified_stmt("SHOW OBJECTS IN ACCOUNT"); | ||
| snowflake().verified_stmt("SHOW OBJECTS IN DATABASE"); | ||
| snowflake().verified_stmt("SHOW OBJECTS IN DATABASE abc"); | ||
| snowflake().verified_stmt("SHOW OBJECTS IN SCHEMA"); | ||
| snowflake().verified_stmt("SHOW OBJECTS IN SCHEMA abc"); | ||
| snowflake().verified_stmt("SHOW TERSE OBJECTS"); | ||
| snowflake().verified_stmt("SHOW TERSE OBJECTS IN abc"); | ||
| snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc"); | ||
| snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b'"); | ||
| snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10"); | ||
| snowflake() | ||
| .verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10 FROM 'x'"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_show_tables() { | ||
| snowflake().verified_stmt("SHOW TABLES"); | ||
|
|
||
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?