mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-08 01:15:00 +00:00
Add the alter table ON COMMIT option to Snowflake (#1606)
This commit is contained in:
parent
7867ba3cf0
commit
c69839102a
3 changed files with 33 additions and 16 deletions
|
@ -377,6 +377,10 @@ pub fn parse_create_table(
|
||||||
parser.expect_token(&Token::RParen)?;
|
parser.expect_token(&Token::RParen)?;
|
||||||
builder = builder.with_tags(Some(tags));
|
builder = builder.with_tags(Some(tags));
|
||||||
}
|
}
|
||||||
|
Keyword::ON if parser.parse_keyword(Keyword::COMMIT) => {
|
||||||
|
let on_commit = Some(parser.parse_create_table_on_commit()?);
|
||||||
|
builder = builder.on_commit(on_commit);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return parser.expected("end of statement", next_token);
|
return parser.expected("end of statement", next_token);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6155,22 +6155,11 @@ impl<'a> Parser<'a> {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let on_commit: Option<OnCommit> =
|
let on_commit = if self.parse_keywords(&[Keyword::ON, Keyword::COMMIT]) {
|
||||||
if self.parse_keywords(&[Keyword::ON, Keyword::COMMIT, Keyword::DELETE, Keyword::ROWS])
|
Some(self.parse_create_table_on_commit()?)
|
||||||
{
|
} else {
|
||||||
Some(OnCommit::DeleteRows)
|
None
|
||||||
} else if self.parse_keywords(&[
|
};
|
||||||
Keyword::ON,
|
|
||||||
Keyword::COMMIT,
|
|
||||||
Keyword::PRESERVE,
|
|
||||||
Keyword::ROWS,
|
|
||||||
]) {
|
|
||||||
Some(OnCommit::PreserveRows)
|
|
||||||
} else if self.parse_keywords(&[Keyword::ON, Keyword::COMMIT, Keyword::DROP]) {
|
|
||||||
Some(OnCommit::Drop)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let strict = self.parse_keyword(Keyword::STRICT);
|
let strict = self.parse_keyword(Keyword::STRICT);
|
||||||
|
|
||||||
|
@ -6226,6 +6215,21 @@ impl<'a> Parser<'a> {
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn parse_create_table_on_commit(&mut self) -> Result<OnCommit, ParserError> {
|
||||||
|
if self.parse_keywords(&[Keyword::DELETE, Keyword::ROWS]) {
|
||||||
|
Ok(OnCommit::DeleteRows)
|
||||||
|
} else if self.parse_keywords(&[Keyword::PRESERVE, Keyword::ROWS]) {
|
||||||
|
Ok(OnCommit::PreserveRows)
|
||||||
|
} else if self.parse_keywords(&[Keyword::DROP]) {
|
||||||
|
Ok(OnCommit::Drop)
|
||||||
|
} else {
|
||||||
|
parser_err!(
|
||||||
|
"Expecting DELETE ROWS, PRESERVE ROWS or DROP",
|
||||||
|
self.peek_token()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse configuration like partitioning, clustering information during the table creation.
|
/// Parse configuration like partitioning, clustering information during the table creation.
|
||||||
///
|
///
|
||||||
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_2)
|
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_2)
|
||||||
|
|
|
@ -355,6 +355,15 @@ fn test_snowflake_create_table_column_comment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_snowflake_create_table_on_commit() {
|
||||||
|
snowflake().verified_stmt(
|
||||||
|
r#"CREATE LOCAL TEMPORARY TABLE "AAA"."foo" ("bar" INTEGER) ON COMMIT PRESERVE ROWS"#,
|
||||||
|
);
|
||||||
|
snowflake().verified_stmt(r#"CREATE TABLE "AAA"."foo" ("bar" INTEGER) ON COMMIT DELETE ROWS"#);
|
||||||
|
snowflake().verified_stmt(r#"CREATE TABLE "AAA"."foo" ("bar" INTEGER) ON COMMIT DROP"#);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_snowflake_create_local_table() {
|
fn test_snowflake_create_local_table() {
|
||||||
match snowflake().verified_stmt("CREATE TABLE my_table (a INT)") {
|
match snowflake().verified_stmt("CREATE TABLE my_table (a INT)") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue