Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4956,6 +4956,8 @@ pub enum Statement {
copy_options: KeyValueOptions,
/// Optional comment.
comment: Option<String>,
/// Trailing `WITH TAG (<t> = '<v>' [, ...])` clause; empty when absent.
with_tags: Vec<Tag>,
},
/// ```sql
/// ALTER STAGE [IF EXISTS] <name> { SET ... | RENAME TO <new_name> }
Expand Down Expand Up @@ -7563,6 +7565,7 @@ impl fmt::Display for Statement {
file_format,
copy_options,
comment,
with_tags,
..
} => {
write!(
Expand All @@ -7584,6 +7587,9 @@ impl fmt::Display for Statement {
if comment.is_some() {
write!(f, " COMMENT='{}'", comment.as_ref().unwrap())?;
}
if !with_tags.is_empty() {
write!(f, " WITH TAG ({})", display_comma_separated(with_tags))?;
}
Ok(())
}
Statement::AlterStage {
Expand Down
22 changes: 22 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@ impl Dialect for SnowflakeDialect {
return Some(Ok(stmt));
}

// ALTER STAGE [IF EXISTS] <name> { SET TAG | UNSET TAG } — intercept only
// the tag form. Every other ALTER STAGE form (SET <property>, RENAME TO)
// fails the closure (the `TAG` keyword is absent) and falls through to
// parse_alter_stage, which keeps the bare (name-less) form a syntax error.
if let Ok(Some(stmt)) = parser.maybe_parse(|p| {
p.expect_keywords(&[Keyword::ALTER, Keyword::STAGE])?;
parse_alter_object_set_tags(p, ObjectType::Stage)
}) {
return Some(Ok(stmt));
}

if parser.parse_keywords(&[Keyword::ALTER, Keyword::STAGE]) {
// ALTER STAGE
return Some(parse_alter_stage(parser));
Expand Down Expand Up @@ -1963,6 +1974,16 @@ pub fn parse_create_stage(
comment,
} = parse_stage_properties(parser)?;

// Trailing `WITH TAG (<t> = '<v>' [, ...])`. The property loop above breaks
// on the `WITH` keyword, so the clause is naturally trailing-only.
let mut with_tags = Vec::new();
if parser.parse_keyword(Keyword::WITH) {
parser.expect_keyword(Keyword::TAG)?;
parser.expect_token(&Token::LParen)?;
with_tags = parser.parse_comma_separated(Parser::parse_tag)?;
parser.expect_token(&Token::RParen)?;
}

Ok(Statement::CreateStage {
or_replace,
temporary,
Expand All @@ -1973,6 +1994,7 @@ pub fn parse_create_stage(
file_format,
copy_options,
comment,
with_tags,
})
}

Expand Down
Loading