Skip to content

Commit f9de697

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

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
@@ -4608,6 +4608,11 @@ pub enum Statement {
46084608
comment: Option<String>,
46094609
},
46104610
/// ```sql
4611+
/// SHOW EXTERNAL VOLUMES [LIKE '<pattern>']
4612+
/// ```
4613+
/// See <https://docs.snowflake.com/en/sql-reference/sql/show-external-volumes>
4614+
ShowExternalVolumes(ShowExternalVolumes),
4615+
/// ```sql
46114616
/// CREATE [ OR REPLACE ] WAREHOUSE [ IF NOT EXISTS ] <name>
46124617
/// [ [ WITH ] <property> = <value> [ ... ] ]
46134618
/// ```
@@ -6344,6 +6349,7 @@ impl fmt::Display for Statement {
63446349
}
63456350
Ok(())
63466351
}
6352+
Statement::ShowExternalVolumes(s) => write!(f, "{s}"),
63476353
Statement::CreateWarehouse(s) => write!(f, "{s}"),
63486354
Statement::CopyIntoSnowflake {
63496355
kind,
@@ -11180,6 +11186,28 @@ pub struct ShowObjects {
1118011186
pub show_options: ShowStatementOptions,
1118111187
}
1118211188

11189+
/// ```sql
11190+
/// SHOW EXTERNAL VOLUMES [LIKE '<pattern>']
11191+
/// ```
11192+
/// See <https://docs.snowflake.com/en/sql-reference/sql/show-external-volumes>
11193+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11194+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11195+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11196+
pub struct ShowExternalVolumes {
11197+
/// Optional filter (e.g. `LIKE`).
11198+
pub filter: Option<ShowStatementFilter>,
11199+
}
11200+
11201+
impl fmt::Display for ShowExternalVolumes {
11202+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11203+
write!(f, "SHOW EXTERNAL VOLUMES")?;
11204+
if let Some(ref filter) = self.filter {
11205+
write!(f, " {filter}")?;
11206+
}
11207+
Ok(())
11208+
}
11209+
}
11210+
1118311211
/// MSSQL's json null clause
1118411212
///
1118511213
/// ```plaintext
@@ -12675,6 +12703,12 @@ impl From<CreateUser> for Statement {
1267512703
}
1267612704
}
1267712705

12706+
impl From<ShowExternalVolumes> for Statement {
12707+
fn from(s: ShowExternalVolumes) -> Self {
12708+
Self::ShowExternalVolumes(s)
12709+
}
12710+
}
12711+
1267812712
impl From<CreateWarehouse> for Statement {
1267912713
fn from(c: CreateWarehouse) -> Self {
1268012714
Self::CreateWarehouse(c)

‎src/ast/spans.rs‎

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

‎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;
@@ -390,6 +391,9 @@ impl Dialect for SnowflakeDialect {
390391
}
391392

392393
if parser.parse_keyword(Keyword::SHOW) {
394+
if parser.parse_keywords(&[Keyword::EXTERNAL, Keyword::VOLUMES]) {
395+
return Some(parse_show_external_volumes(parser));
396+
}
393397
let terse = parser.parse_keyword(Keyword::TERSE);
394398
if parser.parse_keyword(Keyword::OBJECTS) {
395399
return Some(parse_show_objects(terse, parser));
@@ -2018,3 +2022,9 @@ fn parse_multi_table_insert_when_clauses(
20182022

20192023
Ok((when_clauses, else_clause))
20202024
}
2025+
2026+
/// Parse `SHOW EXTERNAL VOLUMES [LIKE '<pattern>']`
2027+
fn parse_show_external_volumes(parser: &mut Parser) -> Result<Statement, ParserError> {
2028+
let filter = parser.parse_show_statement_filter()?;
2029+
Ok(ShowExternalVolumes { filter }.into())
2030+
}

‎src/keywords.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ define_keywords!(
11641164
VIRTUAL,
11651165
VOLATILE,
11661166
VOLUME,
1167+
VOLUMES,
11671168
WAITFOR,
11681169
WAREHOUSE,
11691170
WAREHOUSES,

‎tests/sqlparser_snowflake.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5071,3 +5071,25 @@ fn test_stage_name_delimiters() {
50715071
ParserError::ParserError("Expected: stage name identifier, found: .".to_string()),
50725072
);
50735073
}
5074+
5075+
#[test]
5076+
fn test_show_external_volumes() {
5077+
match snowflake().verified_stmt("SHOW EXTERNAL VOLUMES") {
5078+
Statement::ShowExternalVolumes(ShowExternalVolumes { filter }) => {
5079+
assert!(filter.is_none());
5080+
}
5081+
_ => unreachable!(),
5082+
}
5083+
}
5084+
5085+
#[test]
5086+
fn test_show_external_volumes_like() {
5087+
match snowflake().verified_stmt("SHOW EXTERNAL VOLUMES LIKE 'my_%'") {
5088+
Statement::ShowExternalVolumes(ShowExternalVolumes {
5089+
filter: Some(ShowStatementFilter::Like(pattern)),
5090+
}) => {
5091+
assert_eq!("my_%", pattern);
5092+
}
5093+
_ => unreachable!(),
5094+
}
5095+
}

0 commit comments

Comments
 (0)