Skip to content

Commit 0a4fcd2

Browse files
committed
Suggested done
1 parent dd4d972 commit 0a4fcd2

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

src/ast/mod.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,31 +2980,11 @@ pub enum Statement {
29802980
show_options: ShowStatementOptions,
29812981
},
29822982
/// ```sql
2983-
/// SHOW [ TERSE ] OBJECTS [ LIKE '<pattern>' ]
2984-
/// [ IN
2985-
/// {
2986-
/// ACCOUNT |
2987-
///
2988-
/// DATABASE |
2989-
/// DATABASE <database_name> |
2990-
///
2991-
/// SCHEMA |
2992-
/// SCHEMA <schema_name> |
2993-
/// <schema_name>
2994-
///
2995-
/// APPLICATION <application_name> |
2996-
/// APPLICATION PACKAGE <application_package_name> |
2997-
/// }
2998-
/// ]
2999-
/// [ STARTS WITH '<name_string>' ]
3000-
/// [ LIMIT <rows> [ FROM '<name_string>' ] ]
2983+
/// SHOW OBJECTS LIKE 'line%' IN mydb.public
30012984
/// ```
30022985
/// Snowflake-specific statement
30032986
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
3004-
ShowObjects {
3005-
terse: bool,
3006-
show_options: ShowStatementOptions,
3007-
},
2987+
ShowObjects(ShowObjects),
30082988
/// ```sql
30092989
/// SHOW TABLES
30102990
/// ```
@@ -4668,10 +4648,10 @@ impl fmt::Display for Statement {
46684648
)?;
46694649
Ok(())
46704650
}
4671-
Statement::ShowObjects {
4651+
Statement::ShowObjects(ShowObjects {
46724652
terse,
46734653
show_options,
4674-
} => {
4654+
}) => {
46754655
write!(
46764656
f,
46774657
"SHOW {terse}OBJECTS{show_options}",
@@ -8310,6 +8290,14 @@ impl fmt::Display for ShowStatementIn {
83108290
}
83118291
}
83128292

8293+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8294+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8295+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8296+
pub struct ShowObjects {
8297+
pub terse: bool,
8298+
pub show_options: ShowStatementOptions,
8299+
}
8300+
83138301
/// MSSQL's json null clause
83148302
///
83158303
/// ```plaintext

src/dialect/snowflake.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ use crate::ast::helpers::stmt_data_loading::{
2323
StageLoadSelectItem, StageParamsObject,
2424
};
2525
use crate::ast::{
26-
ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident,
27-
IdentityParameters, IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind,
28-
IdentityPropertyOrder, ObjectName, RowAccessPolicy, Statement, TagsColumnOption,
29-
WrappedCollection,
26+
ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident, IdentityParameters, IdentityProperty,
27+
IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, ObjectName,
28+
RowAccessPolicy, ShowObjects, Statement, TagsColumnOption, WrappedCollection,
3029
};
3130
use crate::dialect::{Dialect, Precedence};
3231
use crate::keywords::Keyword;
@@ -1073,8 +1072,8 @@ fn parse_column_tags(parser: &mut Parser, with: bool) -> Result<TagsColumnOption
10731072
/// <https://docs.snowflake.com/en/sql-reference/sql/show-objects>
10741073
fn parse_show_objects(terse: bool, parser: &mut Parser) -> Result<Statement, ParserError> {
10751074
let show_options = parser.parse_show_stmt_options()?;
1076-
Ok(Statement::ShowObjects {
1075+
Ok(Statement::ShowObjects(ShowObjects {
10771076
terse,
10781077
show_options,
1079-
})
1078+
}))
10801079
}

tests/sqlparser_snowflake.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,6 +2992,27 @@ fn test_parse_show_objects() {
29922992
snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10");
29932993
snowflake()
29942994
.verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc STARTS WITH 'b' LIMIT 10 FROM 'x'");
2995+
match snowflake().verified_stmt("SHOW TERSE OBJECTS LIKE '%test%' IN abc") {
2996+
Statement::ShowObjects(ShowObjects {
2997+
terse,
2998+
show_options,
2999+
}) => {
3000+
assert!(terse);
3001+
let name = show_options
3002+
.show_in
3003+
.unwrap()
3004+
.parent_name
3005+
.unwrap()
3006+
.to_string();
3007+
assert_eq!("abc", name);
3008+
let like = match show_options.filter_position {
3009+
Some(ShowStatementFilterPosition::Infix(ShowStatementFilter::Like(val))) => val,
3010+
_ => unreachable!(),
3011+
};
3012+
assert_eq!("%test%", like);
3013+
}
3014+
_ => unreachable!(),
3015+
}
29953016
}
29963017

29973018
#[test]

0 commit comments

Comments
 (0)