diff --git a/.changes/unreleased/Under the Hood-20231005-115800.yaml b/.changes/unreleased/Under the Hood-20231005-115800.yaml new file mode 100644 index 000000000..a5b56ed72 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20231005-115800.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Support for use of type aliases in contract column data_type +time: 2023-10-05T11:58:00.719136-04:00 +custom: + Author: gshank + Issue: "953" diff --git a/dbt/adapters/bigquery/column.py b/dbt/adapters/bigquery/column.py index 1820a6ba7..1bdf4323d 100644 --- a/dbt/adapters/bigquery/column.py +++ b/dbt/adapters/bigquery/column.py @@ -13,12 +13,9 @@ @dataclass(init=False) class BigQueryColumn(Column): TYPE_LABELS = { - "STRING": "STRING", - "TIMESTAMP": "TIMESTAMP", + "TEXT": "STRING", "FLOAT": "FLOAT64", "INTEGER": "INT64", - "BOOLEAN": "BOOLEAN", - "RECORD": "RECORD", } fields: List[Self] # type: ignore mode: str # type: ignore diff --git a/tests/functional/adapter/constraints/test_constraints.py b/tests/functional/adapter/constraints/test_constraints.py index c8c0c11e2..013f2948b 100644 --- a/tests/functional/adapter/constraints/test_constraints.py +++ b/tests/functional/adapter/constraints/test_constraints.py @@ -47,7 +47,7 @@ _expected_sql_bigquery = """ create or replace table ( - id integer not null primary key not enforced references (id) not enforced, + id INT64 not null primary key not enforced references (id) not enforced, color string, date_day string ) @@ -79,12 +79,9 @@ """ # Different on BigQuery: -# - does not support a data type named 'text' (TODO handle this via type translation/aliasing!) -constraints_yml = model_schema_yml.replace("text", "string") -model_constraints_yml = constrained_model_schema_yml.replace("text", "string") -model_contract_header_schema_yml = model_contract_header_schema_yml.replace("text", "string") -model_fk_constraint_schema_yml = model_fk_constraint_schema_yml.replace("text", "string") -constrained_model_schema_yml = constrained_model_schema_yml.replace("text", "string") +# Switch from text to string handled by aliasing +constraints_yml = model_schema_yml +model_constraints_yml = constrained_model_schema_yml my_model_contract_sql_header_sql = """ {{ @@ -334,7 +331,7 @@ def models(self): def expected_sql(self): return """ create or replace table ( - id integer not null, + id INT64 not null, color string, date_day string, primary key (id) not enforced, @@ -361,14 +358,14 @@ class TestBigQueryConstraintQuotedColumn(BaseConstraintQuotedColumn): def models(self): return { "my_model.sql": my_model_with_quoted_column_name_sql, - "constraints_schema.yml": model_quoted_column_schema_yml.replace("text", "string"), + "constraints_schema.yml": model_quoted_column_schema_yml, } @pytest.fixture(scope="class") def expected_sql(self): return """ create or replace table ( - id integer not null, + id INT64 not null, `from` string not null, date_day string )