From 56a0bf66f668894a67f16bcf8a3d3cb0218fd69b Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:33:12 +0000 Subject: [PATCH] fix(bigquery): keep a column's and a struct field's OPTIONS A table column's OPTIONS (...) and a struct field's OPTIONS (...) were read and dropped, so CREATE TABLE d.t (a INT64 OPTIONS(description='ab')) and the same with 'cd', or with no OPTIONS, gave one tree. ALTER TABLE ... ADD COLUMN had the same loss. The column keeps its entries in ColumnDef.options and the struct field appends them to StructField.options after NOT NULL, the fields other dialects already fill. The other OPTIONS lists the parser reads without a field (constraint OPTIONS, UNDROP and SELECT WITH ... OPTIONS) are opaque gaps that keep their text. --- .../src/parse/_helpers/commands/alters.rs | 2 +- .../src/parse/_helpers/values/typenames.rs | 2 +- .../src/parse/tests/test_parse.rs | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/crates/sqlquack-syntax-bigquery/src/parse/_helpers/commands/alters.rs b/crates/sqlquack-syntax-bigquery/src/parse/_helpers/commands/alters.rs index 429beaad4..0f7151419 100644 --- a/crates/sqlquack-syntax-bigquery/src/parse/_helpers/commands/alters.rs +++ b/crates/sqlquack-syntax-bigquery/src/parse/_helpers/commands/alters.rs @@ -502,7 +502,7 @@ impl Parser<'_> { } } if self.eat_kw("OPTIONS") { - self.options_list()?; + column.options = self.options_list()?; } Ok(column) } diff --git a/crates/sqlquack-syntax-bigquery/src/parse/_helpers/values/typenames.rs b/crates/sqlquack-syntax-bigquery/src/parse/_helpers/values/typenames.rs index 6093d627f..b3ddf4bed 100644 --- a/crates/sqlquack-syntax-bigquery/src/parse/_helpers/values/typenames.rs +++ b/crates/sqlquack-syntax-bigquery/src/parse/_helpers/values/typenames.rs @@ -258,7 +258,7 @@ impl Parser<'_> { } if self.kw("OPTIONS") && self.char_at(1, '(') { self.at += 1; - self.options_list()?; + options.extend(self.options_list()?); } Ok(StructField::with_options_and_comment( name, data_type, options, None, diff --git a/crates/sqlquack-syntax-bigquery/src/parse/tests/test_parse.rs b/crates/sqlquack-syntax-bigquery/src/parse/tests/test_parse.rs index c34f74641..348913758 100644 --- a/crates/sqlquack-syntax-bigquery/src/parse/tests/test_parse.rs +++ b/crates/sqlquack-syntax-bigquery/src/parse/tests/test_parse.rs @@ -1477,6 +1477,36 @@ fn given_unpivot_labels_and_ddl_options_when_parsing_then_they_are_kept() { other_sql: "CREATE VIEW d.v (a, b) AS SELECT 1, 2", expected_same: false, }, + TreePairTestCase { + description: "a table column's OPTIONS values are kept", + sql: "CREATE TABLE d.t (a INT64 OPTIONS(description='ab'))", + other_sql: "CREATE TABLE d.t (a INT64 OPTIONS(description='cd'))", + expected_same: false, + }, + TreePairTestCase { + description: "a table column's OPTIONS are kept", + sql: "CREATE TABLE d.t (a INT64 NOT NULL OPTIONS(description='ab'))", + other_sql: "CREATE TABLE d.t (a INT64 NOT NULL)", + expected_same: false, + }, + TreePairTestCase { + description: "an added column's OPTIONS are kept", + sql: "ALTER TABLE d.t ADD COLUMN a INT64 OPTIONS(description='ab')", + other_sql: "ALTER TABLE d.t ADD COLUMN a INT64 OPTIONS(description='cd')", + expected_same: false, + }, + TreePairTestCase { + description: "a struct field's OPTIONS are kept", + sql: "CREATE TABLE d.t (a STRUCT)", + other_sql: "CREATE TABLE d.t (a STRUCT)", + expected_same: false, + }, + TreePairTestCase { + description: "a struct field's NOT NULL stays apart from its OPTIONS", + sql: "CREATE TABLE d.t (a STRUCT)", + other_sql: "CREATE TABLE d.t (a STRUCT)", + expected_same: false, + }, TreePairTestCase { description: "OPTIONS += is not =", sql: "CREATE VIEW d.v OPTIONS(labels += [('a', 'b')]) AS SELECT 1 x",