1717
1818#[ cfg( not( feature = "std" ) ) ]
1919use crate :: alloc:: string:: ToString ;
20+ use crate :: ast:: helpers:: attached_token:: AttachedToken ;
2021use crate :: ast:: helpers:: key_value_options:: {
2122 KeyValueOption , KeyValueOptionKind , KeyValueOptions , KeyValueOptionsDelimiter ,
2223} ;
@@ -26,11 +27,12 @@ use crate::ast::helpers::stmt_data_loading::{
2627 FileStagingCommand , StageLoadSelectItem , StageLoadSelectItemKind , StageParamsObject ,
2728} ;
2829use crate :: ast:: {
29- CatalogSyncNamespaceMode , ColumnOption , ColumnPolicy , ColumnPolicyProperty , ContactEntry ,
30- CopyIntoSnowflakeKind , CreateTableLikeKind , DollarQuotedString , Ident , IdentityParameters ,
31- IdentityProperty , IdentityPropertyFormatKind , IdentityPropertyKind , IdentityPropertyOrder ,
32- InitializeKind , ObjectName , ObjectNamePart , RefreshModeKind , RowAccessPolicy , ShowObjects ,
33- SqlOption , Statement , StorageSerializationPolicy , TagsColumnOption , Value , WrappedCollection ,
30+ AlterTable , AlterTableOperation , AlterTableType , CatalogSyncNamespaceMode , ColumnOption ,
31+ ColumnPolicy , ColumnPolicyProperty , ContactEntry , CopyIntoSnowflakeKind , CreateTableLikeKind ,
32+ DollarQuotedString , Ident , IdentityParameters , IdentityProperty , IdentityPropertyFormatKind ,
33+ IdentityPropertyKind , IdentityPropertyOrder , InitializeKind , ObjectName , ObjectNamePart ,
34+ RefreshModeKind , RowAccessPolicy , ShowObjects , SqlOption , Statement ,
35+ StorageSerializationPolicy , TagsColumnOption , Value , WrappedCollection ,
3436} ;
3537use crate :: dialect:: { Dialect , Precedence } ;
3638use crate :: keywords:: Keyword ;
@@ -214,6 +216,11 @@ impl Dialect for SnowflakeDialect {
214216 return Some ( parser. parse_begin_exception_end ( ) ) ;
215217 }
216218
219+ if parser. parse_keywords ( & [ Keyword :: ALTER , Keyword :: DYNAMIC , Keyword :: TABLE ] ) {
220+ // ALTER DYNAMIC TABLE
221+ return Some ( parse_alter_dynamic_table ( parser) ) ;
222+ }
223+
217224 if parser. parse_keywords ( & [ Keyword :: ALTER , Keyword :: SESSION ] ) {
218225 // ALTER SESSION
219226 let set = match parser. parse_one_of_keywords ( & [ Keyword :: SET , Keyword :: UNSET ] ) {
@@ -604,6 +611,44 @@ fn parse_file_staging_command(kw: Keyword, parser: &mut Parser) -> Result<Statem
604611 }
605612}
606613
614+ /// Parse snowflake alter dynamic table.
615+ /// <https://docs.snowflake.com/en/sql-reference/sql/alter-table>
616+ fn parse_alter_dynamic_table ( parser : & mut Parser ) -> Result < Statement , ParserError > {
617+ // Use parse_object_name(true) to support IDENTIFIER() function
618+ let table_name = parser. parse_object_name ( true ) ?;
619+
620+ // Parse the operation (REFRESH, SUSPEND, or RESUME)
621+ let operation = if parser. parse_keyword ( Keyword :: REFRESH ) {
622+ AlterTableOperation :: Refresh
623+ } else if parser. parse_keyword ( Keyword :: SUSPEND ) {
624+ AlterTableOperation :: Suspend
625+ } else if parser. parse_keyword ( Keyword :: RESUME ) {
626+ AlterTableOperation :: Resume
627+ } else {
628+ return parser. expected (
629+ "REFRESH, SUSPEND, or RESUME after ALTER DYNAMIC TABLE" ,
630+ parser. peek_token ( ) ,
631+ ) ;
632+ } ;
633+
634+ let end_token = if parser. peek_token_ref ( ) . token == Token :: SemiColon {
635+ parser. peek_token_ref ( ) . clone ( )
636+ } else {
637+ parser. get_current_token ( ) . clone ( )
638+ } ;
639+
640+ Ok ( Statement :: AlterTable ( AlterTable {
641+ name : table_name,
642+ if_exists : false ,
643+ only : false ,
644+ operations : vec ! [ operation] ,
645+ location : None ,
646+ on_cluster : None ,
647+ table_type : Some ( AlterTableType :: Dynamic ) ,
648+ end_token : AttachedToken ( end_token) ,
649+ } ) )
650+ }
651+
607652/// Parse snowflake alter session.
608653/// <https://docs.snowflake.com/en/sql-reference/sql/alter-session>
609654fn parse_alter_session ( parser : & mut Parser , set : bool ) -> Result < Statement , ParserError > {
0 commit comments