Skip to content

Commit 4221563

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 e60e9f8 commit 4221563

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
@@ -2906,6 +2906,32 @@ pub enum Statement {
29062906
show_options: ShowStatementOptions,
29072907
},
29082908
/// ```sql
2909+
/// SHOW [ TERSE ] OBJECTS [ LIKE '<pattern>' ]
2910+
/// [ IN
2911+
/// {
2912+
/// ACCOUNT |
2913+
///
2914+
/// DATABASE |
2915+
/// DATABASE <database_name> |
2916+
///
2917+
/// SCHEMA |
2918+
/// SCHEMA <schema_name> |
2919+
/// <schema_name>
2920+
///
2921+
/// APPLICATION <application_name> |
2922+
/// APPLICATION PACKAGE <application_package_name> |
2923+
/// }
2924+
/// ]
2925+
/// [ STARTS WITH '<name_string>' ]
2926+
/// [ LIMIT <rows> [ FROM '<name_string>' ] ]
2927+
/// ```
2928+
/// Snowflake-specific statement
2929+
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
2930+
ShowObjects {
2931+
terse: bool,
2932+
show_options: ShowStatementOptions,
2933+
},
2934+
/// ```sql
29092935
/// SHOW TABLES
29102936
/// ```
29112937
ShowTables {
@@ -4472,6 +4498,17 @@ impl fmt::Display for Statement {
44724498
)?;
44734499
Ok(())
44744500
}
4501+
Statement::ShowObjects {
4502+
terse,
4503+
show_options,
4504+
} => {
4505+
write!(
4506+
f,
4507+
"SHOW {terse}OBJECTS{show_options}",
4508+
terse = if *terse { "TERSE " } else { "" },
4509+
)?;
4510+
Ok(())
4511+
}
44754512
Statement::ShowTables {
44764513
terse,
44774514
history,

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ impl Spanned for Statement {
485485
Statement::DropPolicy { .. } => Span::empty(),
486486
Statement::ShowDatabases { .. } => Span::empty(),
487487
Statement::ShowSchemas { .. } => Span::empty(),
488+
Statement::ShowObjects { .. } => Span::empty(),
488489
Statement::ShowViews { .. } => Span::empty(),
489490
Statement::LISTEN { .. } => Span::empty(),
490491
Statement::NOTIFY { .. } => Span::empty(),

src/dialect/snowflake.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ impl Dialect for SnowflakeDialect {
169169
return Some(parse_copy_into(parser));
170170
}
171171

172+
if parser.parse_keyword(Keyword::SHOW) {
173+
let terse = parser.parse_keyword(Keyword::TERSE);
174+
if parser.parse_keyword(Keyword::OBJECTS) {
175+
return Some(parse_show_objects(terse, parser));
176+
}
177+
}
178+
172179
None
173180
}
174181

@@ -962,3 +969,15 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result<TagsColumnOption
962969

963970
Ok(TagsColumnOption { with, tags })
964971
}
972+
973+
/// Parse snowflake show objects.
974+
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
975+
fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result<Statement, ParserError> {
976+
let show_options = parser.parse_show_stmt_options()?;
977+
Ok(
978+
Statement::ShowObjects {
979+
terse,
980+
show_options,
981+
}
982+
)
983+
}

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ define_keywords!(
545545
NUMERIC,
546546
NVARCHAR,
547547
OBJECT,
548+
OBJECTS,
548549
OCCURRENCES_REGEX,
549550
OCTETS,
550551
OCTET_LENGTH,

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12892,8 +12892,8 @@ impl<'a> Parser<'a> {
1289212892
}
1289312893
false
1289412894
}
12895-
12896-
fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
12895+
12896+
pub fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
1289712897
let show_in;
1289812898
let mut filter_position = None;
1289912899
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
@@ -2949,6 +2949,24 @@ fn test_parse_show_schemas() {
29492949
snowflake().verified_stmt("SHOW SCHEMAS IN DATABASE STARTS WITH 'abc' LIMIT 20 FROM 'xyz'");
29502950
}
29512951

2952+
#[test]
2953+
fn test_parse_show_objects() {
2954+
snowflake().verified_stmt("SHOW OBJECTS");
2955+
snowflake().verified_stmt("SHOW OBJECTS IN abc");
2956+
snowflake().verified_stmt("SHOW OBJECTS LIKE '%test%' IN abc");
2957+
snowflake().verified_stmt("SHOW OBJECTS IN ACCOUNT");
2958+
snowflake().verified_stmt("SHOW OBJECTS IN DATABASE");
2959+
snowflake().verified_stmt("SHOW OBJECTS IN DATABASE abc");
2960+
snowflake().verified_stmt("SHOW OBJECTS IN SCHEMA");
2961+
snowflake().verified_stmt("SHOW OBJECTS IN SCHEMA abc");
2962+
snowflake().verified_stmt("SHOW TERSE OBJECTS");
2963+
snowflake().verified_stmt("SHOW TERSE OBJECTS IN abc");
2964+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc");
2965+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b'");
2966+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10");
2967+
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10 FROM 'x'");
2968+
}
2969+
29522970
#[test]
29532971
fn test_parse_show_tables() {
29542972
snowflake().verified_stmt("SHOW TABLES");

0 commit comments

Comments
 (0)