Skip to content

Commit ed28b88

Browse files
committed
Added alter external table .. add partition column support
1 parent da84b91 commit ed28b88

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/ast/ddl.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,13 @@ pub enum AlterTableOperation {
375375
///
376376
/// Note: this is Snowflake specific for dynamic tables <https://docs.snowflake.com/en/sql-reference/sql/alter-table>
377377
Refresh,
378+
/// `ADD PARTITION COLUMN <column_name> <data_type>`
379+
///
380+
/// Note: this is Snowflake specific for external tables <https://docs.snowflake.com/en/sql-reference/sql/alter-external-table>
381+
AddPartitionColumn {
382+
column_name: Ident,
383+
data_type: DataType,
384+
},
378385
/// `SUSPEND`
379386
///
380387
/// Note: this is Snowflake specific for dynamic tables <https://docs.snowflake.com/en/sql-reference/sql/alter-table>
@@ -866,6 +873,12 @@ impl fmt::Display for AlterTableOperation {
866873
AlterTableOperation::Refresh => {
867874
write!(f, "REFRESH")
868875
}
876+
AlterTableOperation::AddPartitionColumn {
877+
column_name,
878+
data_type,
879+
} => {
880+
write!(f, "ADD PARTITION COLUMN {column_name} {data_type}")
881+
}
869882
AlterTableOperation::Suspend => {
870883
write!(f, "SUSPEND")
871884
}

src/ast/spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ impl Spanned for AlterTableOperation {
11461146
AlterTableOperation::SuspendRecluster => Span::empty(),
11471147
AlterTableOperation::ResumeRecluster => Span::empty(),
11481148
AlterTableOperation::Refresh => Span::empty(),
1149+
AlterTableOperation::AddPartitionColumn { column_name, .. } => column_name.span,
11491150
AlterTableOperation::Suspend => Span::empty(),
11501151
AlterTableOperation::Resume => Span::empty(),
11511152
AlterTableOperation::Algorithm { .. } => Span::empty(),

src/dialect/snowflake.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,16 @@ fn parse_alter_external_table(parser: &mut Parser) -> Result<Statement, ParserEr
668668
AlterTableOperation::RenameTable {
669669
table_name: RenameTableNameKind::To(new_table_name),
670670
}
671+
} else if parser.parse_keywords(&[Keyword::ADD, Keyword::PARTITION, Keyword::COLUMN]) {
672+
let column_name = parser.parse_identifier()?;
673+
let data_type = parser.parse_data_type()?;
674+
AlterTableOperation::AddPartitionColumn {
675+
column_name,
676+
data_type,
677+
}
671678
} else {
672679
return parser.expected(
673-
"REFRESH or RENAME TO after ALTER EXTERNAL TABLE",
680+
"REFRESH, RENAME TO, or ADD PARTITION COLUMN after ALTER EXTERNAL TABLE",
674681
parser.peek_token(),
675682
);
676683
};

tests/sqlparser_snowflake.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,4 +4641,5 @@ fn test_alter_external_table() {
46414641
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table REFRESH");
46424642
snowflake().verified_stmt("ALTER EXTERNAL TABLE my_database.my_schema.my_external_table REFRESH");
46434643
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table RENAME TO new_table_name");
4644+
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table ADD PARTITION COLUMN column_name VARCHAR");
46444645
}

0 commit comments

Comments
 (0)