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
108 changes: 83 additions & 25 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4766,6 +4766,18 @@ pub enum Statement {
comment: Option<String>,
},
/// ```sql
/// ALTER STAGE [IF EXISTS] <name> { SET ... | RENAME TO <new_name> }
/// ```
/// See <https://docs.snowflake.com/en/sql-reference/sql/alter-stage>
AlterStage {
/// Stage name.
name: ObjectName,
/// `IF EXISTS` flag.
if_exists: bool,
/// The alter operation.
operation: AlterStageOperation,
},
/// ```sql
/// CREATE [OR REPLACE] WAREHOUSE [IF NOT EXISTS] <name>
/// ```
CreateWarehouse {
Expand Down Expand Up @@ -6839,6 +6851,17 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::AlterStage {
name,
if_exists,
operation,
} => {
write!(
f,
"ALTER STAGE {if_exists}{name} {operation}",
if_exists = if *if_exists { "IF EXISTS " } else { "" },
)
}
Statement::CreateWarehouse {
or_replace,
if_not_exists,
Expand Down Expand Up @@ -7001,18 +7024,10 @@ impl fmt::Display for Statement {
}
write!(f, ")")?;
if let Some(val) = allow_writes {
write!(
f,
" ALLOW_WRITES = {}",
if *val { "TRUE" } else { "FALSE" }
)?;
write!(f, " ALLOW_WRITES = {}", if *val { "TRUE" } else { "FALSE" })?;
}
if let Some(ref c) = comment {
write!(
f,
" COMMENT = '{}'",
value::escape_single_quote_string(c)
)?;
write!(f, " COMMENT = '{}'", value::escape_single_quote_string(c))?;
}
Ok(())
}
Expand Down Expand Up @@ -7140,20 +7155,12 @@ impl fmt::Display for Statement {
if let Some(ref auth) = rest_authentication {
write!(f, " REST_AUTHENTICATION = ({auth})")?;
}
write!(
f,
" ENABLED = {}",
if *enabled { "TRUE" } else { "FALSE" }
)?;
write!(f, " ENABLED = {}", if *enabled { "TRUE" } else { "FALSE" })?;
if let Some(secs) = refresh_interval_seconds {
write!(f, " REFRESH_INTERVAL_SECONDS = {secs}")?;
}
if let Some(ref c) = comment {
write!(
f,
" COMMENT = '{}'",
value::escape_single_quote_string(c)
)?;
write!(f, " COMMENT = '{}'", value::escape_single_quote_string(c))?;
}
Ok(())
}
Expand Down Expand Up @@ -12138,6 +12145,61 @@ impl fmt::Display for AlterFileFormatOperation {
}
}

/// Operations for `ALTER STAGE`.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum AlterStageOperation {
/// `RENAME TO <new_name>`
RenameTo(ObjectName),
/// `SET <stage-params/options>` — the same property groups as `CREATE STAGE`.
Set {
/// Internal/external stage parameters (URL, STORAGE_INTEGRATION,
/// CREDENTIALS, ENCRYPTION, ENDPOINT).
stage_params: StageParamsObject,
/// Directory table parameters (`DIRECTORY = (...)`).
directory_table_params: KeyValueOptions,
/// File format options (`FILE_FORMAT = (...)`).
file_format: KeyValueOptions,
/// Copy options (`COPY_OPTIONS = (...)`).
copy_options: KeyValueOptions,
/// Optional `COMMENT` value.
comment: Option<String>,
},
}

impl fmt::Display for AlterStageOperation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AlterStageOperation::RenameTo(name) => {
write!(f, "RENAME TO {name}")
}
AlterStageOperation::Set {
stage_params,
directory_table_params,
file_format,
copy_options,
comment,
} => {
write!(f, "SET{stage_params}")?;
if !directory_table_params.options.is_empty() {
write!(f, " DIRECTORY=({directory_table_params})")?;
}
if !file_format.options.is_empty() {
write!(f, " FILE_FORMAT=({file_format})")?;
}
if !copy_options.options.is_empty() {
write!(f, " COPY_OPTIONS=({copy_options})")?;
}
if let Some(comment) = comment {
write!(f, " COMMENT='{comment}'")?;
}
Ok(())
}
}
}
}

/// A `<key> = <value>` pair inside `ALTER WAREHOUSE … SET …`.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -12388,11 +12450,7 @@ impl fmt::Display for CatalogRestConfig {
write!(f, " CATALOG_API_TYPE = {t}")?;
}
if let Some(ref w) = self.warehouse {
write!(
f,
" WAREHOUSE = '{}'",
value::escape_single_quote_string(w)
)?;
write!(f, " WAREHOUSE = '{}'", value::escape_single_quote_string(w))?;
}
if let Some(ref m) = self.access_delegation_mode {
write!(f, " ACCESS_DELEGATION_MODE = {m}")?;
Expand Down
35 changes: 17 additions & 18 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::{
},
tokenizer::TokenWithSpan,
};
#[cfg(not(feature = "std"))]
use alloc::vec;
use core::iter;

use crate::tokenizer::Span;
Expand All @@ -35,20 +37,19 @@ use super::{
ConflictTarget, ConnectByKind, ConstraintCharacteristics, CopySource, CreateIndex, CreateTable,
CreateTableOptions, Cte, Delete, DoUpdate, ExceptSelectItem, ExcludeSelectItem, Expr,
ExprWithAlias, Fetch, ForIterationSource, ForStatement, ForValues, FromTable, Function,
FunctionArg,
FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList, FunctionArguments, GroupByExpr,
HavingBound, IfStatement, IlikeSelectItem, IndexColumn, Insert, Interpolate, InterpolateExpr,
Join, JoinConstraint, JoinOperator, JsonPath, JsonPathElem, LateralView, LimitClause,
LoopControlStatement, LoopStatement, MatchRecognizePattern, Measure, Merge, MergeAction,
MergeClause, MergeInsertExpr, MergeInsertKind, MergeUpdateExpr, NamedParenthesizedList,
NamedWindowDefinition, ObjectName, ObjectNamePart, Offset, OnConflict, OnConflictAction,
OnInsert, OpenStatement, OrderBy, OrderByExpr, OrderByKind, OutputClause, Parens, Partition,
PartitionBoundValue, PivotValueSource, ProjectionSelect, Query, RaiseStatement,
RaiseStatementValue, ReferentialAction, RenameSelectItem, RepeatStatement, ReplaceSelectElement,
ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SqlOption, Statement, Subscript,
SymbolDefinition, TableAlias, TableAliasColumnDef, TableConstraint, TableFactor, TableObject,
TableOptionsClustered, TableWithJoins, Update, UpdateTableFromKind, Use, Values, ViewColumnDef,
WhileStatement, WildcardAdditionalOptions, With, WithFill,
FunctionArg, FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList, FunctionArguments,
GroupByExpr, HavingBound, IfStatement, IlikeSelectItem, IndexColumn, Insert, Interpolate,
InterpolateExpr, Join, JoinConstraint, JoinOperator, JsonPath, JsonPathElem, LateralView,
LimitClause, LoopControlStatement, LoopStatement, MatchRecognizePattern, Measure, Merge,
MergeAction, MergeClause, MergeInsertExpr, MergeInsertKind, MergeUpdateExpr,
NamedParenthesizedList, NamedWindowDefinition, ObjectName, ObjectNamePart, Offset, OnConflict,
OnConflictAction, OnInsert, OpenStatement, OrderBy, OrderByExpr, OrderByKind, OutputClause,
Parens, Partition, PartitionBoundValue, PivotValueSource, ProjectionSelect, Query,
RaiseStatement, RaiseStatementValue, ReferentialAction, RenameSelectItem, RepeatStatement,
ReplaceSelectElement, ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SqlOption,
Statement, Subscript, SymbolDefinition, TableAlias, TableAliasColumnDef, TableConstraint,
TableFactor, TableObject, TableOptionsClustered, TableWithJoins, Update, UpdateTableFromKind,
Use, Values, ViewColumnDef, WhileStatement, WildcardAdditionalOptions, With, WithFill,
};

/// Given an iterator of spans, return the [Span::union] of all spans.
Expand Down Expand Up @@ -462,6 +463,7 @@ impl Spanned for Statement {
Statement::CreateProcedure { .. } => Span::empty(),
Statement::CreateMacro { .. } => Span::empty(),
Statement::CreateStage { .. } => Span::empty(),
Statement::AlterStage { .. } => Span::empty(),
Statement::Assert { .. } => Span::empty(),
Statement::Grant { .. } => Span::empty(),
Statement::Deny { .. } => Span::empty(),
Expand Down Expand Up @@ -831,10 +833,7 @@ impl Spanned for RepeatStatement {
impl Spanned for LoopControlStatement {
fn span(&self) -> Span {
let LoopControlStatement { kind: _, label } = self;
label
.as_ref()
.map(|l| l.span)
.unwrap_or_else(Span::empty)
label.as_ref().map(|l| l.span).unwrap_or_else(Span::empty)
}
}

Expand Down
Loading
Loading