From c8242d935d763f115cf7cb3efef98880da07f13d Mon Sep 17 00:00:00 2001 From: Martin Sahlen Date: Wed, 15 Jan 2025 15:23:53 +0200 Subject: [PATCH 1/2] Allow empty options for BigQuery --- src/parser/mod.rs | 4 ++++ tests/sqlparser_bigquery.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index ac764a535..0f4097b0e 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -7341,6 +7341,10 @@ impl<'a> Parser<'a> { pub fn parse_options(&mut self, keyword: Keyword) -> Result, ParserError> { if self.parse_keyword(keyword) { self.expect_token(&Token::LParen)?; + if self.peek_token() == Token::RParen { + self.next_token(); + return Ok(vec![]); + } let options = self.parse_comma_separated(Parser::parse_sql_option)?; self.expect_token(&Token::RParen)?; Ok(options) diff --git a/tests/sqlparser_bigquery.rs b/tests/sqlparser_bigquery.rs index 9dfabc014..23ca17715 100644 --- a/tests/sqlparser_bigquery.rs +++ b/tests/sqlparser_bigquery.rs @@ -2244,3 +2244,15 @@ fn test_any_type() { fn test_any_type_dont_break_custom_type() { bigquery_and_generic().verified_stmt("CREATE TABLE foo (x ANY)"); } + +#[test] +fn parse_create_table_with_empty_table_options() { + let sql = "CREATE TABLE foo (x INT64) OPTIONS()"; + bigquery().verified_stmt(sql); +} + +#[test] +fn parse_create_table_with_empty_table_options_and_column_options() { + let sql = "CREATE TABLE db.schema.test (x INT64 OPTIONS(description = 'An optional INTEGER field')) OPTIONS()"; + bigquery().verified_stmt(sql); +} From 8a4ba236b2c97278b916407b093fa567e1ad95c5 Mon Sep 17 00:00:00 2001 From: Martin Abelson Sahlen Date: Thu, 16 Jan 2025 09:58:05 +0200 Subject: [PATCH 2/2] Refactor based on PR feedback --- src/parser/mod.rs | 6 +----- tests/sqlparser_bigquery.rs | 18 ++++++------------ 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 0f4097b0e..861a392d4 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -7341,11 +7341,7 @@ impl<'a> Parser<'a> { pub fn parse_options(&mut self, keyword: Keyword) -> Result, ParserError> { if self.parse_keyword(keyword) { self.expect_token(&Token::LParen)?; - if self.peek_token() == Token::RParen { - self.next_token(); - return Ok(vec![]); - } - let options = self.parse_comma_separated(Parser::parse_sql_option)?; + let options = self.parse_comma_separated0(Parser::parse_sql_option, Token::RParen)?; self.expect_token(&Token::RParen)?; Ok(options) } else { diff --git a/tests/sqlparser_bigquery.rs b/tests/sqlparser_bigquery.rs index 23ca17715..a173a6cc9 100644 --- a/tests/sqlparser_bigquery.rs +++ b/tests/sqlparser_bigquery.rs @@ -473,6 +473,12 @@ fn parse_create_table_with_options() { r#"description = "table option description")"# ); bigquery().verified_stmt(sql); + + let sql = "CREATE TABLE foo (x INT64) OPTIONS()"; + bigquery().verified_stmt(sql); + + let sql = "CREATE TABLE db.schema.test (x INT64 OPTIONS(description = 'An optional INTEGER field')) OPTIONS()"; + bigquery().verified_stmt(sql); } #[test] @@ -2244,15 +2250,3 @@ fn test_any_type() { fn test_any_type_dont_break_custom_type() { bigquery_and_generic().verified_stmt("CREATE TABLE foo (x ANY)"); } - -#[test] -fn parse_create_table_with_empty_table_options() { - let sql = "CREATE TABLE foo (x INT64) OPTIONS()"; - bigquery().verified_stmt(sql); -} - -#[test] -fn parse_create_table_with_empty_table_options_and_column_options() { - let sql = "CREATE TABLE db.schema.test (x INT64 OPTIONS(description = 'An optional INTEGER field')) OPTIONS()"; - bigquery().verified_stmt(sql); -}