Skip to content
Open
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
34 changes: 34 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4558,6 +4558,11 @@ pub enum Statement {
comment: Option<String>,
},
/// ```sql
/// SHOW EXTERNAL VOLUMES [LIKE '<pattern>']
/// ```
/// See <https://docs.snowflake.com/en/sql-reference/sql/show-external-volumes>
ShowExternalVolumes(ShowExternalVolumes),
/// ```sql
/// CREATE [ OR REPLACE ] WAREHOUSE [ IF NOT EXISTS ] <name>
/// [ [ WITH ] <property> = <value> [ ... ] ]
/// ```
Expand Down Expand Up @@ -6293,6 +6298,7 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::ShowExternalVolumes(s) => write!(f, "{s}"),
Statement::CreateWarehouse(s) => write!(f, "{s}"),
Statement::CopyIntoSnowflake {
kind,
Expand Down Expand Up @@ -11131,6 +11137,28 @@ pub struct ShowObjects {
pub show_options: ShowStatementOptions,
}

/// ```sql
/// SHOW EXTERNAL VOLUMES [LIKE '<pattern>']
/// ```
/// See <https://docs.snowflake.com/en/sql-reference/sql/show-external-volumes>
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct ShowExternalVolumes {
/// Optional filter (e.g. `LIKE`).
pub filter: Option<ShowStatementFilter>,
}

impl fmt::Display for ShowExternalVolumes {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SHOW EXTERNAL VOLUMES")?;
if let Some(ref filter) = self.filter {
write!(f, " {filter}")?;
}
Ok(())
}
}

/// MSSQL's json null clause
///
/// ```plaintext
Expand Down Expand Up @@ -12626,6 +12654,12 @@ impl From<CreateUser> for Statement {
}
}

impl From<ShowExternalVolumes> for Statement {
fn from(s: ShowExternalVolumes) -> Self {
Self::ShowExternalVolumes(s)
}
}

impl From<CreateWarehouse> for Statement {
fn from(c: CreateWarehouse) -> Self {
Self::CreateWarehouse(c)
Expand Down
1 change: 1 addition & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ impl Spanned for Statement {
Statement::Vacuum(..) => Span::empty(),
Statement::AlterUser(..) => Span::empty(),
Statement::Reset(..) => Span::empty(),
Statement::ShowExternalVolumes(..) => Span::empty(),
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ use crate::ast::{
IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, InitializeKind,
Insert, MultiTableInsertIntoClause, MultiTableInsertType, MultiTableInsertValue,
MultiTableInsertValues, MultiTableInsertWhenClause, ObjectName, ObjectNamePart,
RefreshModeKind, RowAccessPolicy, ShowObjects, SqlOption, Statement, StorageLifecyclePolicy,
StorageSerializationPolicy, TableObject, TagsColumnOption, Value, WrappedCollection,
RefreshModeKind, RowAccessPolicy, ShowExternalVolumes, ShowObjects, SqlOption, Statement,
StorageLifecyclePolicy, StorageSerializationPolicy, TableObject, TagsColumnOption, Value,
WrappedCollection,
};
use crate::dialect::{Dialect, Precedence};
use crate::keywords::Keyword;
Expand Down Expand Up @@ -368,6 +369,9 @@ impl Dialect for SnowflakeDialect {
}

if parser.parse_keyword(Keyword::SHOW) {
if parser.parse_keywords(&[Keyword::EXTERNAL, Keyword::VOLUMES]) {
return Some(parse_show_external_volumes(parser));
}
let terse = parser.parse_keyword(Keyword::TERSE);
if parser.parse_keyword(Keyword::OBJECTS) {
return Some(parse_show_objects(terse, parser));
Expand Down Expand Up @@ -1988,3 +1992,9 @@ fn parse_multi_table_insert_when_clauses(

Ok((when_clauses, else_clause))
}

/// Parse `SHOW EXTERNAL VOLUMES [LIKE '<pattern>']`
fn parse_show_external_volumes(parser: &mut Parser) -> Result<Statement, ParserError> {
let filter = parser.parse_show_statement_filter()?;
Ok(ShowExternalVolumes { filter }.into())
}
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ define_keywords!(
VIRTUAL,
VOLATILE,
VOLUME,
VOLUMES,
WAITFOR,
WAREHOUSE,
WAREHOUSES,
Expand Down
22 changes: 22 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4912,3 +4912,25 @@ fn test_select_dollar_column_from_stage() {
// With table function args, without alias
snowflake().verified_stmt("SELECT $1, $2 FROM @mystage1(file_format => 'myformat')");
}

#[test]
fn test_show_external_volumes() {
match snowflake().verified_stmt("SHOW EXTERNAL VOLUMES") {
Statement::ShowExternalVolumes(ShowExternalVolumes { filter }) => {
assert!(filter.is_none());
}
_ => unreachable!(),
}
}

#[test]
fn test_show_external_volumes_like() {
match snowflake().verified_stmt("SHOW EXTERNAL VOLUMES LIKE 'my_%'") {
Statement::ShowExternalVolumes(ShowExternalVolumes {
filter: Some(ShowStatementFilter::Like(pattern)),
}) => {
assert_eq!("my_%", pattern);
}
_ => unreachable!(),
}
}
Loading