Skip to content

Commit 34d8ca9

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 1aa3d48 commit 34d8ca9

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

src/dialect/snowflake.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ impl Dialect for SnowflakeDialect {
187187
return Some(parse_file_staging_command(kw, parser));
188188
}
189189

190+
if parser.parse_keyword(Keyword::SHOW) {
191+
let terse = parser.parse_keyword(Keyword::TERSE);
192+
if parser.parse_keyword(Keyword::OBJECTS) {
193+
return Some(parse_show_objects(terse, parser));
194+
}
195+
}
196+
197+
198+
190199
None
191200
}
192201

@@ -264,7 +273,7 @@ impl Dialect for SnowflakeDialect {
264273
fn is_select_item_alias(&self, explicit: bool, kw: &Keyword, parser: &mut Parser) -> bool {
265274
explicit
266275
|| match kw {
267-
// The following keywords can be considered an alias as long as
276+
// The following keywords can be considered an alias as long as
268277
// they are not followed by other tokens that may change their meaning
269278
// e.g. `SELECT * EXCEPT (col1) FROM tbl`
270279
Keyword::EXCEPT
@@ -286,8 +295,8 @@ impl Dialect for SnowflakeDialect {
286295
false
287296
}
288297

289-
// Reserved keywords by the Snowflake dialect, which seem to be less strictive
290-
// than what is listed in `keywords::RESERVED_FOR_COLUMN_ALIAS`. The following
298+
// Reserved keywords by the Snowflake dialect, which seem to be less strictive
299+
// than what is listed in `keywords::RESERVED_FOR_COLUMN_ALIAS`. The following
291300
// keywords were tested with the this statement: `SELECT 1 <KW>`.
292301
Keyword::FROM
293302
| Keyword::GROUP
@@ -966,7 +975,7 @@ fn parse_session_options(parser: &mut Parser, set: bool) -> Result<Vec<DataLoadi
966975
});
967976
Ok(())
968977
}
969-
978+
970979
},
971980
_ => parser.expected("another option", parser.peek_token()),
972981
}?;
@@ -1115,3 +1124,15 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result<TagsColumnOption
11151124

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

tests/sqlparser_snowflake.rs

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

2978+
#[test]
2979+
fn test_parse_show_objects() {
2980+
snowflake().verified_stmt("SHOW OBJECTS");
2981+
snowflake().verified_stmt("SHOW OBJECTS IN abc");
2982+
snowflake().verified_stmt("SHOW OBJECTS LIKE '%test%' IN abc");
2983+
snowflake().verified_stmt("SHOW OBJECTS IN ACCOUNT");
2984+
snowflake().verified_stmt("SHOW OBJECTS IN DATABASE");
2985+
snowflake().verified_stmt("SHOW OBJECTS IN DATABASE abc");
2986+
snowflake().verified_stmt("SHOW OBJECTS IN SCHEMA");
2987+
snowflake().verified_stmt("SHOW OBJECTS IN SCHEMA abc");
2988+
snowflake().verified_stmt("SHOW TERSE OBJECTS");
2989+
snowflake().verified_stmt("SHOW TERSE OBJECTS IN abc");
2990+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc");
2991+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b'");
2992+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10");
2993+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10 FROM 'x'");
2994+
}
2995+
29782996
#[test]
29792997
fn test_parse_show_tables() {
29802998
snowflake().verified_stmt("SHOW TABLES");

0 commit comments

Comments
 (0)