Skip to content

Commit 247b082

Browse files
DanCodedThisDenys Tsomenko
authored andcommitted
Add ShowObjects statement (#2)
* Added ShowObjects statement * Parsing, next tests * Small comment * Tests done according to other SHOW statements * Removed unnecessary comments
1 parent 9aa4475 commit 247b082

File tree

6 files changed

+78
-2
lines changed

6 files changed

+78
-2
lines changed

src/ast/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,6 +2943,32 @@ pub enum Statement {
29432943
show_options: ShowStatementOptions,
29442944
},
29452945
/// ```sql
2946+
/// SHOW [ TERSE ] OBJECTS [ LIKE '<pattern>' ]
2947+
/// [ IN
2948+
/// {
2949+
/// ACCOUNT |
2950+
///
2951+
/// DATABASE |
2952+
/// DATABASE <database_name> |
2953+
///
2954+
/// SCHEMA |
2955+
/// SCHEMA <schema_name> |
2956+
/// <schema_name>
2957+
///
2958+
/// APPLICATION <application_name> |
2959+
/// APPLICATION PACKAGE <application_package_name> |
2960+
/// }
2961+
/// ]
2962+
/// [ STARTS WITH '<name_string>' ]
2963+
/// [ LIMIT <rows> [ FROM '<name_string>' ] ]
2964+
/// ```
2965+
/// Snowflake-specific statement
2966+
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
2967+
ShowObjects {
2968+
terse: bool,
2969+
show_options: ShowStatementOptions,
2970+
},
2971+
/// ```sql
29462972
/// SHOW TABLES
29472973
/// ```
29482974
ShowTables {
@@ -4605,6 +4631,17 @@ impl fmt::Display for Statement {
46054631
)?;
46064632
Ok(())
46074633
}
4634+
Statement::ShowObjects {
4635+
terse,
4636+
show_options,
4637+
} => {
4638+
write!(
4639+
f,
4640+
"SHOW {terse}OBJECTS{show_options}",
4641+
terse = if *terse { "TERSE " } else { "" },
4642+
)?;
4643+
Ok(())
4644+
}
46084645
Statement::ShowTables {
46094646
terse,
46104647
history,

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ impl Spanned for Statement {
489489
Statement::DropPolicy { .. } => Span::empty(),
490490
Statement::ShowDatabases { .. } => Span::empty(),
491491
Statement::ShowSchemas { .. } => Span::empty(),
492+
Statement::ShowObjects { .. } => Span::empty(),
492493
Statement::ShowViews { .. } => Span::empty(),
493494
Statement::LISTEN { .. } => Span::empty(),
494495
Statement::NOTIFY { .. } => Span::empty(),

src/dialect/snowflake.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ impl Dialect for SnowflakeDialect {
182182
return Some(parse_file_staging_command(kw, parser));
183183
}
184184

185+
if parser.parse_keyword(Keyword::SHOW) {
186+
let terse = parser.parse_keyword(Keyword::TERSE);
187+
if parser.parse_keyword(Keyword::OBJECTS) {
188+
return Some(parse_show_objects(terse, parser));
189+
}
190+
}
191+
185192
None
186193
}
187194

@@ -1049,3 +1056,15 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result<TagsColumnOption
10491056

10501057
Ok(TagsColumnOption { with, tags })
10511058
}
1059+
1060+
/// Parse snowflake show objects.
1061+
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
1062+
fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result<Statement, ParserError> {
1063+
let show_options = parser.parse_show_stmt_options()?;
1064+
Ok(
1065+
Statement::ShowObjects {
1066+
terse,
1067+
show_options,
1068+
}
1069+
)
1070+
}

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ define_keywords!(
566566
NUMERIC,
567567
NVARCHAR,
568568
OBJECT,
569+
OBJECTS,
569570
OCCURRENCES_REGEX,
570571
OCTETS,
571572
OCTET_LENGTH,

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13808,8 +13808,8 @@ impl<'a> Parser<'a> {
1380813808
}
1380913809
false
1381013810
}
13811-
13812-
fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
13811+
13812+
pub fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
1381313813
let show_in;
1381413814
let mut filter_position = None;
1381513815
if self.dialect.supports_show_like_before_in() {

tests/sqlparser_snowflake.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,6 +2955,24 @@ fn test_parse_show_schemas() {
29552955
snowflake().verified_stmt("SHOW SCHEMAS IN DATABASE STARTS WITH 'abc' LIMIT 20 FROM 'xyz'");
29562956
}
29572957

2958+
#[test]
2959+
fn test_parse_show_objects() {
2960+
snowflake().verified_stmt("SHOW OBJECTS");
2961+
snowflake().verified_stmt("SHOW OBJECTS IN abc");
2962+
snowflake().verified_stmt("SHOW OBJECTS LIKE '%test%' IN abc");
2963+
snowflake().verified_stmt("SHOW OBJECTS IN ACCOUNT");
2964+
snowflake().verified_stmt("SHOW OBJECTS IN DATABASE");
2965+
snowflake().verified_stmt("SHOW OBJECTS IN DATABASE abc");
2966+
snowflake().verified_stmt("SHOW OBJECTS IN SCHEMA");
2967+
snowflake().verified_stmt("SHOW OBJECTS IN SCHEMA abc");
2968+
snowflake().verified_stmt("SHOW TERSE OBJECTS");
2969+
snowflake().verified_stmt("SHOW TERSE OBJECTS IN abc");
2970+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc");
2971+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b'");
2972+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10");
2973+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10 FROM 'x'");
2974+
}
2975+
29582976
#[test]
29592977
fn test_parse_show_tables() {
29602978
snowflake().verified_stmt("SHOW TABLES");

0 commit comments

Comments
 (0)