From d82bb7538b586dbe3420cbd6a80aac9cb884cf92 Mon Sep 17 00:00:00 2001 From: DanCodedThis Date: Fri, 31 Jan 2025 16:38:05 +0200 Subject: [PATCH 1/5] Added ShowObjects statement --- src/ast/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ src/ast/spans.rs | 1 + src/keywords.rs | 1 + 3 files changed, 39 insertions(+) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 6f189ed4b..5d53049b6 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -2948,6 +2948,32 @@ pub enum Statement { show_options: ShowStatementOptions, }, /// ```sql + /// SHOW [ TERSE ] OBJECTS [ LIKE '' ] + /// [ IN + /// { + /// ACCOUNT | + /// + /// DATABASE | + /// DATABASE | + /// + /// SCHEMA | + /// SCHEMA | + /// + /// + /// APPLICATION | + /// APPLICATION PACKAGE | + /// } + /// ] + /// [ STARTS WITH '' ] + /// [ LIMIT [ FROM '' ] ] + /// ``` + /// Snowflake-specific statement + /// + ShowObjects { + terse: bool, + options: ShowStatementOptions, + }, + /// ```sql /// SHOW TABLES /// ``` ShowTables { @@ -4692,6 +4718,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, diff --git a/src/ast/spans.rs b/src/ast/spans.rs index 71a1fd097..c8cb1dc98 100644 --- a/src/ast/spans.rs +++ b/src/ast/spans.rs @@ -515,6 +515,7 @@ impl Spanned for Statement { Statement::DropPolicy { .. } => Span::empty(), Statement::ShowDatabases { .. } => Span::empty(), Statement::ShowSchemas { .. } => Span::empty(), + Statement::ShowObjects { .. } => Span::empty(), Statement::ShowViews { .. } => Span::empty(), Statement::LISTEN { .. } => Span::empty(), Statement::NOTIFY { .. } => Span::empty(), diff --git a/src/keywords.rs b/src/keywords.rs index d1758c05e..81b70b273 100644 --- a/src/keywords.rs +++ b/src/keywords.rs @@ -560,6 +560,7 @@ define_keywords!( NUMERIC, NVARCHAR, OBJECT, + OBJECTS, OCCURRENCES_REGEX, OCTETS, OCTET_LENGTH, From 43bf54e5c2e4c5dc1f425041a2c69c74085efb85 Mon Sep 17 00:00:00 2001 From: DanCodedThis Date: Fri, 31 Jan 2025 17:32:44 +0200 Subject: [PATCH 2/5] Parsing, next tests --- src/dialect/snowflake.rs | 19 +++++++++++++++++++ src/parser/mod.rs | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/dialect/snowflake.rs b/src/dialect/snowflake.rs index 0cb4afcab..865777eb7 100644 --- a/src/dialect/snowflake.rs +++ b/src/dialect/snowflake.rs @@ -178,6 +178,13 @@ 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)); + } + } + None } @@ -1116,3 +1123,15 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result +fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result { + let options = parser.parse_show_stmt_options()?; + Ok( + Statement::ShowObjects { + terse, + options, + } + ) +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 3cf3c585e..5101680ce 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -13670,8 +13670,9 @@ impl<'a> Parser<'a> { } false } - - fn parse_show_stmt_options(&mut self) -> Result { + + //Made this public to be able to parse it in Snowflake dialect for ShowObjects statement + pub fn parse_show_stmt_options(&mut self) -> Result { let show_in; let mut filter_position = None; if self.dialect.supports_show_like_before_in() { From 20f02c17b83a5b80eaed1574b402c195ca6e6659 Mon Sep 17 00:00:00 2001 From: DanCodedThis Date: Fri, 31 Jan 2025 17:36:16 +0200 Subject: [PATCH 3/5] Small comment --- src/dialect/snowflake.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dialect/snowflake.rs b/src/dialect/snowflake.rs index 865777eb7..1e2772285 100644 --- a/src/dialect/snowflake.rs +++ b/src/dialect/snowflake.rs @@ -1127,6 +1127,8 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result { + //TODO: Copy some functionality of parse_show_stmt_options() into another function, + // since it has more statemtns that we sholdun'ts support let options = parser.parse_show_stmt_options()?; Ok( Statement::ShowObjects { From ed4cb057bd9f1d3fd5043719d103093d13bbb34b Mon Sep 17 00:00:00 2001 From: DanCodedThis Date: Fri, 31 Jan 2025 18:08:32 +0200 Subject: [PATCH 4/5] Tests done according to other SHOW statements --- src/ast/mod.rs | 2 +- src/dialect/snowflake.rs | 4 ++-- tests/sqlparser_snowflake.rs | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 5d53049b6..04bd8e0e4 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -2971,7 +2971,7 @@ pub enum Statement { /// ShowObjects { terse: bool, - options: ShowStatementOptions, + show_options: ShowStatementOptions, }, /// ```sql /// SHOW TABLES diff --git a/src/dialect/snowflake.rs b/src/dialect/snowflake.rs index 1e2772285..a95a31b4e 100644 --- a/src/dialect/snowflake.rs +++ b/src/dialect/snowflake.rs @@ -1129,11 +1129,11 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result Result { //TODO: Copy some functionality of parse_show_stmt_options() into another function, // since it has more statemtns that we sholdun'ts support - let options = parser.parse_show_stmt_options()?; + let show_options = parser.parse_show_stmt_options()?; Ok( Statement::ShowObjects { terse, - options, + show_options, } ) } diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index 0aeca796b..0240ba122 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs @@ -2955,6 +2955,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() { + //Only happy path for now + snowflake().verified_stmt("SHOW OBJECTS"); + 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"); From 40321ce5910e958bb29a58f1695ee210e470dd59 Mon Sep 17 00:00:00 2001 From: DanCodedThis Date: Mon, 3 Feb 2025 14:52:11 +0200 Subject: [PATCH 5/5] Removed unnecessary comments --- src/dialect/snowflake.rs | 2 -- src/parser/mod.rs | 1 - tests/sqlparser_snowflake.rs | 1 - 3 files changed, 4 deletions(-) diff --git a/src/dialect/snowflake.rs b/src/dialect/snowflake.rs index a95a31b4e..a4c453f85 100644 --- a/src/dialect/snowflake.rs +++ b/src/dialect/snowflake.rs @@ -1127,8 +1127,6 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result { - //TODO: Copy some functionality of parse_show_stmt_options() into another function, - // since it has more statemtns that we sholdun'ts support let show_options = parser.parse_show_stmt_options()?; Ok( Statement::ShowObjects { diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 5101680ce..ebb79cfb7 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -13671,7 +13671,6 @@ impl<'a> Parser<'a> { false } - //Made this public to be able to parse it in Snowflake dialect for ShowObjects statement pub fn parse_show_stmt_options(&mut self) -> Result { let show_in; let mut filter_position = None; diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index 0240ba122..8a201253b 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs @@ -2957,7 +2957,6 @@ fn test_parse_show_schemas() { #[test] fn test_parse_show_objects() { - //Only happy path for now snowflake().verified_stmt("SHOW OBJECTS"); snowflake().verified_stmt("SHOW OBJECTS IN abc"); snowflake().verified_stmt("SHOW OBJECTS LIKE '%test%' IN abc");