Skip to content

Commit c0be343

Browse files
committed
Added AlterTableType enum
1 parent ae993f5 commit c0be343

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

src/ast/ddl.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,6 +3553,20 @@ impl Spanned for DropExtension {
35533553
}
35543554
}
35553555

3556+
/// Table type for ALTER TABLE statements.
3557+
/// Used to distinguish between regular tables, Iceberg tables, and Dynamic tables.
3558+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3559+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3560+
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3561+
pub enum AlterTableType {
3562+
/// Iceberg table type
3563+
/// <https://docs.snowflake.com/en/sql-reference/sql/alter-iceberg-table>
3564+
Iceberg,
3565+
/// Dynamic table type
3566+
/// <https://docs.snowflake.com/en/sql-reference/sql/alter-table>
3567+
Dynamic,
3568+
}
3569+
35563570
/// ALTER TABLE statement
35573571
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
35583572
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -3569,24 +3583,18 @@ pub struct AlterTable {
35693583
/// For example: `ALTER TABLE table_name ON CLUSTER cluster_name ADD COLUMN c UInt32`
35703584
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/alter/update)
35713585
pub on_cluster: Option<Ident>,
3572-
/// Snowflake "ICEBERG" clause for Iceberg tables
3573-
/// <https://docs.snowflake.com/en/sql-reference/sql/alter-iceberg-table>
3574-
pub iceberg: bool,
3575-
/// Snowflake "DYNAMIC" clause for Dynamic tables
3576-
/// <https://docs.snowflake.com/en/sql-reference/sql/alter-table>
3577-
pub dynamic: bool,
3586+
/// Table type: None for regular tables, Some(AlterTableType) for Iceberg or Dynamic tables
3587+
pub table_type: Option<AlterTableType>,
35783588
/// Token that represents the end of the statement (semicolon or EOF)
35793589
pub end_token: AttachedToken,
35803590
}
35813591

35823592
impl fmt::Display for AlterTable {
35833593
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3584-
if self.iceberg {
3585-
write!(f, "ALTER ICEBERG TABLE ")?;
3586-
} else if self.dynamic {
3587-
write!(f, "ALTER DYNAMIC TABLE ")?;
3588-
} else {
3589-
write!(f, "ALTER TABLE ")?;
3594+
match &self.table_type {
3595+
Some(AlterTableType::Iceberg) => write!(f, "ALTER ICEBERG TABLE ")?,
3596+
Some(AlterTableType::Dynamic) => write!(f, "ALTER DYNAMIC TABLE ")?,
3597+
None => write!(f, "ALTER TABLE ")?,
35903598
}
35913599

35923600
if self.if_exists {

src/ast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub use self::dcl::{
6161
pub use self::ddl::{
6262
AlterColumnOperation, AlterConnectorOwner, AlterIndexOperation, AlterPolicyOperation,
6363
AlterSchema, AlterSchemaOperation, AlterTable, AlterTableAlgorithm, AlterTableLock,
64-
AlterTableOperation, AlterType, AlterTypeAddValue, AlterTypeAddValuePosition,
64+
AlterTableOperation, AlterTableType, AlterType, AlterTypeAddValue, AlterTypeAddValuePosition,
6565
AlterTypeOperation, AlterTypeRename, AlterTypeRenameValue, ClusteredBy, ColumnDef,
6666
ColumnOption, ColumnOptionDef, ColumnOptions, ColumnPolicy, ColumnPolicyProperty,
6767
ConstraintCharacteristics, CreateConnector, CreateDomain, CreateExtension, CreateFunction,

src/dialect/snowflake.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use crate::ast::helpers::stmt_data_loading::{
2727
FileStagingCommand, StageLoadSelectItem, StageLoadSelectItemKind, StageParamsObject,
2828
};
2929
use crate::ast::{
30-
AlterTable, AlterTableOperation, CatalogSyncNamespaceMode, ColumnOption, ColumnPolicy,
31-
ColumnPolicyProperty, ContactEntry, CopyIntoSnowflakeKind, CreateTableLikeKind,
30+
AlterTable, AlterTableOperation, AlterTableType, CatalogSyncNamespaceMode, ColumnOption,
31+
ColumnPolicy, ColumnPolicyProperty, ContactEntry, CopyIntoSnowflakeKind, CreateTableLikeKind,
3232
DollarQuotedString, Ident, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
3333
IdentityPropertyKind, IdentityPropertyOrder, InitializeKind, ObjectName, ObjectNamePart,
3434
RefreshModeKind, RowAccessPolicy, ShowObjects, SqlOption, Statement,
@@ -644,8 +644,7 @@ fn parse_alter_dynamic_table(parser: &mut Parser) -> Result<Statement, ParserErr
644644
operations: vec![operation],
645645
location: None,
646646
on_cluster: None,
647-
iceberg: false,
648-
dynamic: true,
647+
table_type: Some(AlterTableType::Dynamic),
649648
end_token: AttachedToken(end_token),
650649
}))
651650
}

src/parser/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9461,8 +9461,11 @@ impl<'a> Parser<'a> {
94619461
operations,
94629462
location,
94639463
on_cluster,
9464-
iceberg,
9465-
dynamic: false,
9464+
table_type: if iceberg {
9465+
Some(AlterTableType::Iceberg)
9466+
} else {
9467+
None
9468+
},
94669469
end_token: AttachedToken(end_token),
94679470
}
94689471
.into())

src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub fn alter_table_op_with_name(stmt: Statement, expected_name: &str) -> AlterTa
347347
assert_eq!(alter_table.name.to_string(), expected_name);
348348
assert!(!alter_table.if_exists);
349349
assert!(!alter_table.only);
350-
assert!(!alter_table.iceberg);
350+
assert_eq!(alter_table.table_type, None);
351351
only(alter_table.operations)
352352
}
353353
_ => panic!("Expected ALTER TABLE statement"),

tests/sqlparser_mysql.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,15 +2746,14 @@ fn parse_alter_table_add_column() {
27462746
if_exists,
27472747
only,
27482748
operations,
2749-
iceberg,
2750-
dynamic: _,
2749+
table_type,
27512750
location: _,
27522751
on_cluster: _,
27532752
end_token: _,
27542753
}) => {
27552754
assert_eq!(name.to_string(), "tab");
27562755
assert!(!if_exists);
2757-
assert!(!iceberg);
2756+
assert_eq!(table_type, None);
27582757
assert!(!only);
27592758
assert_eq!(
27602759
operations,

0 commit comments

Comments
 (0)