Skip to content

Add ShowObjects statement #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2948,6 +2948,32 @@ pub enum Statement {
show_options: ShowStatementOptions,
},
/// ```sql
/// SHOW [ TERSE ] OBJECTS [ LIKE '<pattern>' ]
/// [ IN
/// {
/// ACCOUNT |
///
/// DATABASE |
/// DATABASE <database_name> |
///
/// SCHEMA |
/// SCHEMA <schema_name> |
/// <schema_name>
///
/// APPLICATION <application_name> |
/// APPLICATION PACKAGE <application_package_name> |
/// }
/// ]
/// [ STARTS WITH '<name_string>' ]
/// [ LIMIT <rows> [ FROM '<name_string>' ] ]
/// ```
/// Snowflake-specific statement
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
ShowObjects {
terse: bool,
show_options: ShowStatementOptions,
},
/// ```sql
/// SHOW TABLES
/// ```
ShowTables {
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
19 changes: 19 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

Ok(TagsColumnOption { with, tags })
}

/// Parse snowflake show objects.
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result<Statement, ParserError> {
let show_options = parser.parse_show_stmt_options()?;
Ok(
Statement::ShowObjects {
terse,
show_options,
}
)
}
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ define_keywords!(
NUMERIC,
NVARCHAR,
OBJECT,
OBJECTS,
OCCURRENCES_REGEX,
OCTETS,
OCTET_LENGTH,
Expand Down
4 changes: 2 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13670,8 +13670,8 @@ impl<'a> Parser<'a> {
}
false
}

fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove redundant spaces here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They had the space before me. All their functions actually have spaces before them for some reason :)

pub fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
let show_in;
let mut filter_position = None;
if self.dialect.supports_show_like_before_in() {
Expand Down
18 changes: 18 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,24 @@ 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() {
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");
Expand Down