Skip to content

Commit 6db79fb

Browse files
Snowflake: Add SHOW EXTERNAL VOLUMES
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c0054b7 commit 6db79fb

5 files changed

Lines changed: 70 additions & 2 deletions

File tree

‎src/ast/mod.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4558,6 +4558,11 @@ pub enum Statement {
45584558
comment: Option<String>,
45594559
},
45604560
/// ```sql
4561+
/// SHOW EXTERNAL VOLUMES [LIKE '<pattern>']
4562+
/// ```
4563+
/// See <https://docs.snowflake.com/en/sql-reference/sql/show-external-volumes>
4564+
ShowExternalVolumes(ShowExternalVolumes),
4565+
/// ```sql
45614566
/// CREATE [ OR REPLACE ] WAREHOUSE [ IF NOT EXISTS ] <name>
45624567
/// [ [ WITH ] <property> = <value> [ ... ] ]
45634568
/// ```
@@ -6293,6 +6298,7 @@ impl fmt::Display for Statement {
62936298
}
62946299
Ok(())
62956300
}
6301+
Statement::ShowExternalVolumes(s) => write!(f, "{s}"),
62966302
Statement::CreateWarehouse(s) => write!(f, "{s}"),
62976303
Statement::CopyIntoSnowflake {
62986304
kind,
@@ -11131,6 +11137,28 @@ pub struct ShowObjects {
1113111137
pub show_options: ShowStatementOptions,
1113211138
}
1113311139

11140+
/// ```sql
11141+
/// SHOW EXTERNAL VOLUMES [LIKE '<pattern>']
11142+
/// ```
11143+
/// See <https://docs.snowflake.com/en/sql-reference/sql/show-external-volumes>
11144+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11145+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11146+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11147+
pub struct ShowExternalVolumes {
11148+
/// Optional filter (e.g. `LIKE`).
11149+
pub filter: Option<ShowStatementFilter>,
11150+
}
11151+
11152+
impl fmt::Display for ShowExternalVolumes {
11153+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11154+
write!(f, "SHOW EXTERNAL VOLUMES")?;
11155+
if let Some(ref filter) = self.filter {
11156+
write!(f, " {filter}")?;
11157+
}
11158+
Ok(())
11159+
}
11160+
}
11161+
1113411162
/// MSSQL's json null clause
1113511163
///
1113611164
/// ```plaintext
@@ -12626,6 +12654,12 @@ impl From<CreateUser> for Statement {
1262612654
}
1262712655
}
1262812656

12657+
impl From<ShowExternalVolumes> for Statement {
12658+
fn from(s: ShowExternalVolumes) -> Self {
12659+
Self::ShowExternalVolumes(s)
12660+
}
12661+
}
12662+
1262912663
impl From<CreateWarehouse> for Statement {
1263012664
fn from(c: CreateWarehouse) -> Self {
1263112665
Self::CreateWarehouse(c)

‎src/ast/spans.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ impl Spanned for Statement {
523523
Statement::Vacuum(..) => Span::empty(),
524524
Statement::AlterUser(..) => Span::empty(),
525525
Statement::Reset(..) => Span::empty(),
526+
Statement::ShowExternalVolumes(..) => Span::empty(),
526527
}
527528
}
528529
}

‎src/dialect/snowflake.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ use crate::ast::{
3333
IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, InitializeKind,
3434
Insert, MultiTableInsertIntoClause, MultiTableInsertType, MultiTableInsertValue,
3535
MultiTableInsertValues, MultiTableInsertWhenClause, ObjectName, ObjectNamePart,
36-
RefreshModeKind, RowAccessPolicy, ShowObjects, SqlOption, Statement, StorageLifecyclePolicy,
37-
StorageSerializationPolicy, TableObject, TagsColumnOption, Value, WrappedCollection,
36+
RefreshModeKind, RowAccessPolicy, ShowExternalVolumes, ShowObjects, SqlOption, Statement,
37+
StorageLifecyclePolicy, StorageSerializationPolicy, TableObject, TagsColumnOption, Value,
38+
WrappedCollection,
3839
};
3940
use crate::dialect::{Dialect, Precedence};
4041
use crate::keywords::Keyword;
@@ -368,6 +369,9 @@ impl Dialect for SnowflakeDialect {
368369
}
369370

370371
if parser.parse_keyword(Keyword::SHOW) {
372+
if parser.parse_keywords(&[Keyword::EXTERNAL, Keyword::VOLUMES]) {
373+
return Some(parse_show_external_volumes(parser));
374+
}
371375
let terse = parser.parse_keyword(Keyword::TERSE);
372376
if parser.parse_keyword(Keyword::OBJECTS) {
373377
return Some(parse_show_objects(terse, parser));
@@ -1988,3 +1992,9 @@ fn parse_multi_table_insert_when_clauses(
19881992

19891993
Ok((when_clauses, else_clause))
19901994
}
1995+
1996+
/// Parse `SHOW EXTERNAL VOLUMES [LIKE '<pattern>']`
1997+
fn parse_show_external_volumes(parser: &mut Parser) -> Result<Statement, ParserError> {
1998+
let filter = parser.parse_show_statement_filter()?;
1999+
Ok(ShowExternalVolumes { filter }.into())
2000+
}

‎src/keywords.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@ define_keywords!(
11621162
VIRTUAL,
11631163
VOLATILE,
11641164
VOLUME,
1165+
VOLUMES,
11651166
WAITFOR,
11661167
WAREHOUSE,
11671168
WAREHOUSES,

‎tests/sqlparser_snowflake.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4912,3 +4912,25 @@ fn test_select_dollar_column_from_stage() {
49124912
// With table function args, without alias
49134913
snowflake().verified_stmt("SELECT $1, $2 FROM @mystage1(file_format => 'myformat')");
49144914
}
4915+
4916+
#[test]
4917+
fn test_show_external_volumes() {
4918+
match snowflake().verified_stmt("SHOW EXTERNAL VOLUMES") {
4919+
Statement::ShowExternalVolumes(ShowExternalVolumes { filter }) => {
4920+
assert!(filter.is_none());
4921+
}
4922+
_ => unreachable!(),
4923+
}
4924+
}
4925+
4926+
#[test]
4927+
fn test_show_external_volumes_like() {
4928+
match snowflake().verified_stmt("SHOW EXTERNAL VOLUMES LIKE 'my_%'") {
4929+
Statement::ShowExternalVolumes(ShowExternalVolumes {
4930+
filter: Some(ShowStatementFilter::Like(pattern)),
4931+
}) => {
4932+
assert_eq!("my_%", pattern);
4933+
}
4934+
_ => unreachable!(),
4935+
}
4936+
}

0 commit comments

Comments
 (0)