Skip to content

Commit 930264a

Browse files
committed
Added relative path to refresh parsing
1 parent ed28b88 commit 930264a

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

src/ast/ddl.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,15 @@ pub enum AlterTableOperation {
371371
DropClusteringKey,
372372
SuspendRecluster,
373373
ResumeRecluster,
374-
/// `REFRESH`
374+
/// `REFRESH [ '<subpath>' ]`
375375
///
376-
/// Note: this is Snowflake specific for dynamic tables <https://docs.snowflake.com/en/sql-reference/sql/alter-table>
377-
Refresh,
376+
/// Note: this is Snowflake specific for dynamic/external tables
377+
/// <https://docs.snowflake.com/en/sql-reference/sql/alter-dynamic-table>
378+
/// <https://docs.snowflake.com/en/sql-reference/sql/alter-external-table>
379+
Refresh {
380+
/// Optional subpath for external table refresh
381+
subpath: Option<String>,
382+
},
378383
/// `ADD PARTITION COLUMN <column_name> <data_type>`
379384
///
380385
/// Note: this is Snowflake specific for external tables <https://docs.snowflake.com/en/sql-reference/sql/alter-external-table>
@@ -870,8 +875,12 @@ impl fmt::Display for AlterTableOperation {
870875
write!(f, "RESUME RECLUSTER")?;
871876
Ok(())
872877
}
873-
AlterTableOperation::Refresh => {
874-
write!(f, "REFRESH")
878+
AlterTableOperation::Refresh { subpath } => {
879+
write!(f, "REFRESH")?;
880+
if let Some(path) = subpath {
881+
write!(f, " '{path}'")?;
882+
}
883+
Ok(())
875884
}
876885
AlterTableOperation::AddPartitionColumn {
877886
column_name,

src/ast/spans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ impl Spanned for AlterTableOperation {
11451145
AlterTableOperation::DropClusteringKey => Span::empty(),
11461146
AlterTableOperation::SuspendRecluster => Span::empty(),
11471147
AlterTableOperation::ResumeRecluster => Span::empty(),
1148-
AlterTableOperation::Refresh => Span::empty(),
1148+
AlterTableOperation::Refresh { .. } => Span::empty(),
11491149
AlterTableOperation::AddPartitionColumn { column_name, .. } => column_name.span,
11501150
AlterTableOperation::Suspend => Span::empty(),
11511151
AlterTableOperation::Resume => Span::empty(),

src/dialect/snowflake.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ fn parse_alter_dynamic_table(parser: &mut Parser) -> Result<Statement, ParserErr
624624

625625
// Parse the operation (REFRESH, SUSPEND, or RESUME)
626626
let operation = if parser.parse_keyword(Keyword::REFRESH) {
627-
AlterTableOperation::Refresh
627+
AlterTableOperation::Refresh { subpath: None }
628628
} else if parser.parse_keyword(Keyword::SUSPEND) {
629629
AlterTableOperation::Suspend
630630
} else if parser.parse_keyword(Keyword::RESUME) {
@@ -662,7 +662,15 @@ fn parse_alter_external_table(parser: &mut Parser) -> Result<Statement, ParserEr
662662

663663
// Parse the operation
664664
let operation = if parser.parse_keyword(Keyword::REFRESH) {
665-
AlterTableOperation::Refresh
665+
// Optional subpath for refreshing specific partitions
666+
let subpath = match parser.peek_token().token {
667+
Token::SingleQuotedString(s) => {
668+
parser.next_token();
669+
Some(s)
670+
}
671+
_ => None,
672+
};
673+
AlterTableOperation::Refresh { subpath }
666674
} else if parser.parse_keywords(&[Keyword::RENAME, Keyword::TO]) {
667675
let new_table_name = parser.parse_object_name(false)?;
668676
AlterTableOperation::RenameTable {

tests/sqlparser_snowflake.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4639,6 +4639,7 @@ fn test_alter_dynamic_table() {
46394639
#[test]
46404640
fn test_alter_external_table() {
46414641
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table REFRESH");
4642+
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table REFRESH 'year=2025/month=12/'");
46424643
snowflake().verified_stmt("ALTER EXTERNAL TABLE my_database.my_schema.my_external_table REFRESH");
46434644
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table RENAME TO new_table_name");
46444645
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table ADD PARTITION COLUMN column_name VARCHAR");

0 commit comments

Comments
 (0)