Skip to content

Commit 791a9ae

Browse files
committed
Added set auto_refresh parsing for alter external table
1 parent 930264a commit 791a9ae

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/ast/ddl.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,16 @@ pub enum AlterTableOperation {
437437
SetOptionsParens {
438438
options: Vec<SqlOption>,
439439
},
440+
/// `SET key = value` options without parentheses.
441+
///
442+
/// Example:
443+
/// ```sql
444+
/// SET AUTO_REFRESH = TRUE
445+
/// ```
446+
/// [Snowflake](https://docs.snowflake.com/en/sql-reference/sql/alter-external-table)
447+
SetOptions {
448+
options: Vec<SqlOption>,
449+
},
440450
}
441451

442452
/// An `ALTER Policy` (`Statement::AlterPolicy`) operation
@@ -914,6 +924,9 @@ impl fmt::Display for AlterTableOperation {
914924
AlterTableOperation::SetOptionsParens { options } => {
915925
write!(f, "SET ({})", display_comma_separated(options))
916926
}
927+
AlterTableOperation::SetOptions { options } => {
928+
write!(f, "SET {}", display_comma_separated(options))
929+
}
917930
}
918931
}
919932
}

src/ast/spans.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,9 @@ impl Spanned for AlterTableOperation {
11571157
AlterTableOperation::SetOptionsParens { options } => {
11581158
union_spans(options.iter().map(|i| i.span()))
11591159
}
1160+
AlterTableOperation::SetOptions { options } => {
1161+
union_spans(options.iter().map(|i| i.span()))
1162+
}
11601163
}
11611164
}
11621165
}

src/dialect/snowflake.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,22 @@ fn parse_alter_external_table(parser: &mut Parser) -> Result<Statement, ParserEr
683683
column_name,
684684
data_type,
685685
}
686+
} else if parser.parse_keyword(Keyword::SET) {
687+
// Parse SET key = value options (e.g., SET AUTO_REFRESH = TRUE)
688+
let mut options = vec![];
689+
loop {
690+
let key = parser.parse_identifier()?;
691+
parser.expect_token(&Token::Eq)?;
692+
let value = parser.parse_expr()?;
693+
options.push(SqlOption::KeyValue { key, value });
694+
if !parser.consume_token(&Token::Comma) {
695+
break;
696+
}
697+
}
698+
AlterTableOperation::SetOptions { options }
686699
} else {
687700
return parser.expected(
688-
"REFRESH, RENAME TO, or ADD PARTITION COLUMN after ALTER EXTERNAL TABLE",
701+
"REFRESH, RENAME TO, ADD PARTITION COLUMN, or SET after ALTER EXTERNAL TABLE",
689702
parser.peek_token(),
690703
);
691704
};

tests/sqlparser_snowflake.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4643,4 +4643,5 @@ fn test_alter_external_table() {
46434643
snowflake().verified_stmt("ALTER EXTERNAL TABLE my_database.my_schema.my_external_table REFRESH");
46444644
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table RENAME TO new_table_name");
46454645
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table ADD PARTITION COLUMN column_name VARCHAR");
4646+
snowflake().verified_stmt("ALTER EXTERNAL TABLE some_table SET AUTO_REFRESH = true");
46464647
}

0 commit comments

Comments
 (0)