Skip to content

Commit 177c37a

Browse files
authored
Add ShowObjects statement (#2)
* Added ShowObjects statement * Parsing, next tests * Small comment * Tests done according to other SHOW statements * Removed unnecessary comments
1 parent 663959d commit 177c37a

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
@@ -2948,6 +2948,32 @@ pub enum Statement {
29482948
show_options: ShowStatementOptions,
29492949
},
29502950
/// ```sql
2951+
/// SHOW [ TERSE ] OBJECTS [ LIKE '<pattern>' ]
2952+
/// [ IN
2953+
/// {
2954+
/// ACCOUNT |
2955+
///
2956+
/// DATABASE |
2957+
/// DATABASE <database_name> |
2958+
///
2959+
/// SCHEMA |
2960+
/// SCHEMA <schema_name> |
2961+
/// <schema_name>
2962+
///
2963+
/// APPLICATION <application_name> |
2964+
/// APPLICATION PACKAGE <application_package_name> |
2965+
/// }
2966+
/// ]
2967+
/// [ STARTS WITH '<name_string>' ]
2968+
/// [ LIMIT <rows> [ FROM '<name_string>' ] ]
2969+
/// ```
2970+
/// Snowflake-specific statement
2971+
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
2972+
ShowObjects {
2973+
terse: bool,
2974+
show_options: ShowStatementOptions,
2975+
},
2976+
/// ```sql
29512977
/// SHOW TABLES
29522978
/// ```
29532979
ShowTables {
@@ -4692,6 +4718,17 @@ impl fmt::Display for Statement {
46924718
)?;
46934719
Ok(())
46944720
}
4721+
Statement::ShowObjects {
4722+
terse,
4723+
show_options,
4724+
} => {
4725+
write!(
4726+
f,
4727+
"SHOW {terse}OBJECTS{show_options}",
4728+
terse = if *terse { "TERSE " } else { "" },
4729+
)?;
4730+
Ok(())
4731+
}
46954732
Statement::ShowTables {
46964733
terse,
46974734
history,

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ impl Spanned for Statement {
515515
Statement::DropPolicy { .. } => Span::empty(),
516516
Statement::ShowDatabases { .. } => Span::empty(),
517517
Statement::ShowSchemas { .. } => Span::empty(),
518+
Statement::ShowObjects { .. } => Span::empty(),
518519
Statement::ShowViews { .. } => Span::empty(),
519520
Statement::LISTEN { .. } => Span::empty(),
520521
Statement::NOTIFY { .. } => Span::empty(),

src/dialect/snowflake.rs

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

181+
if parser.parse_keyword(Keyword::SHOW) {
182+
let terse = parser.parse_keyword(Keyword::TERSE);
183+
if parser.parse_keyword(Keyword::OBJECTS) {
184+
return Some(parse_show_objects(terse, parser));
185+
}
186+
}
187+
181188
None
182189
}
183190

@@ -1116,3 +1123,15 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result<TagsColumnOption
11161123

11171124
Ok(TagsColumnOption { with, tags })
11181125
}
1126+
1127+
/// Parse snowflake show objects.
1128+
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
1129+
fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result<Statement, ParserError> {
1130+
let show_options = parser.parse_show_stmt_options()?;
1131+
Ok(
1132+
Statement::ShowObjects {
1133+
terse,
1134+
show_options,
1135+
}
1136+
)
1137+
}

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ define_keywords!(
560560
NUMERIC,
561561
NVARCHAR,
562562
OBJECT,
563+
OBJECTS,
563564
OCCURRENCES_REGEX,
564565
OCTETS,
565566
OCTET_LENGTH,

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13670,8 +13670,8 @@ impl<'a> Parser<'a> {
1367013670
}
1367113671
false
1367213672
}
13673-
13674-
fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
13673+
13674+
pub fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
1367513675
let show_in;
1367613676
let mut filter_position = None;
1367713677
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)