Skip to content

Commit 3f4002f

Browse files
VedinDanCodedThis
andauthored
Add ShowObjects statement after rebase(#7)
* Add ShowObjects statement (#2) * Added ShowObjects statement * Parsing, next tests * Small comment * Tests done according to other SHOW statements * Removed unnecessary comments * Fix test in other that object cases. Cargo fmt. --------- Co-authored-by: DanCodedThis <[email protected]>
1 parent 1aa3d48 commit 3f4002f

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

src/dialect/snowflake.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ use crate::ast::helpers::stmt_data_loading::{
2323
StageLoadSelectItem, StageParamsObject,
2424
};
2525
use crate::ast::{
26-
ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident, IdentityParameters, IdentityProperty,
27-
IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, ObjectName,
28-
RowAccessPolicy, Statement, TagsColumnOption, WrappedCollection,
26+
ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident,
27+
IdentityParameters, IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind,
28+
IdentityPropertyOrder, ObjectName, RowAccessPolicy, Statement, TagsColumnOption,
29+
WrappedCollection,
2930
};
3031
use crate::dialect::{Dialect, Precedence};
3132
use crate::keywords::Keyword;
@@ -187,6 +188,17 @@ impl Dialect for SnowflakeDialect {
187188
return Some(parse_file_staging_command(kw, parser));
188189
}
189190

191+
if parser.parse_keyword(Keyword::SHOW) {
192+
let terse = parser.parse_keyword(Keyword::TERSE);
193+
if parser.parse_keyword(Keyword::OBJECTS) {
194+
return Some(parse_show_objects(terse, parser));
195+
} else {
196+
return Some(parser.parse_show());
197+
}
198+
}
199+
200+
201+
190202
None
191203
}
192204

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

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
301+
// Reserved keywords by the Snowflake dialect, which seem to be less strictive
302+
// than what is listed in `keywords::RESERVED_FOR_COLUMN_ALIAS`. The following
291303
// keywords were tested with the this statement: `SELECT 1 <KW>`.
292304
Keyword::FROM
293305
| Keyword::GROUP
@@ -966,7 +978,7 @@ fn parse_session_options(parser: &mut Parser, set: bool) -> Result<Vec<DataLoadi
966978
});
967979
Ok(())
968980
}
969-
981+
970982
},
971983
_ => parser.expected("another option", parser.peek_token()),
972984
}?;
@@ -1115,3 +1127,13 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result<TagsColumnOption
11151127

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

src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14164,7 +14164,7 @@ impl<'a> Parser<'a> {
1416414164
}
1416514165
false
1416614166
}
14167-
14167+
1416814168
pub fn parse_show_stmt_options(&mut self) -> Result<ShowStatementOptions, ParserError> {
1416914169
let show_in;
1417014170
let mut filter_position = None;

tests/sqlparser_snowflake.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,6 +2975,25 @@ 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()
2994+
.verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10 FROM 'x'");
2995+
}
2996+
29782997
#[test]
29792998
fn test_parse_show_tables() {
29802999
snowflake().verified_stmt("SHOW TABLES");

0 commit comments

Comments
 (0)