Skip to content

Commit 56a0bf6

Browse files
committed
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.
1 parent b938ec5 commit 56a0bf6

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎crates/sqlquack-syntax-bigquery/src/parse/_helpers/commands/alters.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl Parser<'_> {
502502
}
503503
}
504504
if self.eat_kw("OPTIONS") {
505-
self.options_list()?;
505+
column.options = self.options_list()?;
506506
}
507507
Ok(column)
508508
}

‎crates/sqlquack-syntax-bigquery/src/parse/_helpers/values/typenames.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl Parser<'_> {
258258
}
259259
if self.kw("OPTIONS") && self.char_at(1, '(') {
260260
self.at += 1;
261-
self.options_list()?;
261+
options.extend(self.options_list()?);
262262
}
263263
Ok(StructField::with_options_and_comment(
264264
name, data_type, options, None,

‎crates/sqlquack-syntax-bigquery/src/parse/tests/test_parse.rs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,36 @@ fn given_unpivot_labels_and_ddl_options_when_parsing_then_they_are_kept() {
14771477
other_sql: "CREATE VIEW d.v (a, b) AS SELECT 1, 2",
14781478
expected_same: false,
14791479
},
1480+
TreePairTestCase {
1481+
description: "a table column's OPTIONS values are kept",
1482+
sql: "CREATE TABLE d.t (a INT64 OPTIONS(description='ab'))",
1483+
other_sql: "CREATE TABLE d.t (a INT64 OPTIONS(description='cd'))",
1484+
expected_same: false,
1485+
},
1486+
TreePairTestCase {
1487+
description: "a table column's OPTIONS are kept",
1488+
sql: "CREATE TABLE d.t (a INT64 NOT NULL OPTIONS(description='ab'))",
1489+
other_sql: "CREATE TABLE d.t (a INT64 NOT NULL)",
1490+
expected_same: false,
1491+
},
1492+
TreePairTestCase {
1493+
description: "an added column's OPTIONS are kept",
1494+
sql: "ALTER TABLE d.t ADD COLUMN a INT64 OPTIONS(description='ab')",
1495+
other_sql: "ALTER TABLE d.t ADD COLUMN a INT64 OPTIONS(description='cd')",
1496+
expected_same: false,
1497+
},
1498+
TreePairTestCase {
1499+
description: "a struct field's OPTIONS are kept",
1500+
sql: "CREATE TABLE d.t (a STRUCT<x INT64 OPTIONS(description='ab')>)",
1501+
other_sql: "CREATE TABLE d.t (a STRUCT<x INT64 OPTIONS(description='cd')>)",
1502+
expected_same: false,
1503+
},
1504+
TreePairTestCase {
1505+
description: "a struct field's NOT NULL stays apart from its OPTIONS",
1506+
sql: "CREATE TABLE d.t (a STRUCT<x INT64 NOT NULL OPTIONS(description='ab')>)",
1507+
other_sql: "CREATE TABLE d.t (a STRUCT<x INT64 OPTIONS(description='ab')>)",
1508+
expected_same: false,
1509+
},
14801510
TreePairTestCase {
14811511
description: "OPTIONS += is not =",
14821512
sql: "CREATE VIEW d.v OPTIONS(labels += [('a', 'b')]) AS SELECT 1 x",

0 commit comments

Comments
 (0)