Skip to content

Add ShowObjects statement #7

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 2 commits into from
Feb 5, 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
36 changes: 29 additions & 7 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ use crate::ast::helpers::stmt_data_loading::{
StageLoadSelectItem, StageParamsObject,
};
use crate::ast::{
ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident, IdentityParameters, IdentityProperty,
IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, ObjectName,
RowAccessPolicy, Statement, TagsColumnOption, WrappedCollection,
ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident,
IdentityParameters, IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind,
IdentityPropertyOrder, ObjectName, RowAccessPolicy, Statement, TagsColumnOption,
WrappedCollection,
};
use crate::dialect::{Dialect, Precedence};
use crate::keywords::Keyword;
Expand Down Expand Up @@ -187,6 +188,17 @@ 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));
} else {
return Some(parser.parse_show());
}
}



None
}

Expand Down Expand Up @@ -264,7 +276,7 @@ impl Dialect for SnowflakeDialect {
fn is_select_item_alias(&self, explicit: bool, kw: &Keyword, parser: &mut Parser) -> bool {
explicit
|| match kw {
// The following keywords can be considered an alias as long as
// The following keywords can be considered an alias as long as
// they are not followed by other tokens that may change their meaning
// e.g. `SELECT * EXCEPT (col1) FROM tbl`
Keyword::EXCEPT
Expand All @@ -286,8 +298,8 @@ impl Dialect for SnowflakeDialect {
false
}

// Reserved keywords by the Snowflake dialect, which seem to be less strictive
// than what is listed in `keywords::RESERVED_FOR_COLUMN_ALIAS`. The following
// Reserved keywords by the Snowflake dialect, which seem to be less strictive
// than what is listed in `keywords::RESERVED_FOR_COLUMN_ALIAS`. The following
// keywords were tested with the this statement: `SELECT 1 <KW>`.
Keyword::FROM
| Keyword::GROUP
Expand Down Expand Up @@ -966,7 +978,7 @@ fn parse_session_options(parser: &mut Parser, set: bool) -> Result<Vec<DataLoadi
});
Ok(())
}

},
_ => parser.expected("another option", parser.peek_token()),
}?;
Expand Down Expand Up @@ -1115,3 +1127,13 @@ 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,
})
}
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14164,7 +14164,7 @@ impl<'a> Parser<'a> {
}
false
}

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