Skip to content

Commit

Permalink
Support type aliasing in contracts (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank authored Oct 10, 2023
1 parent 4976d54 commit 5396aa0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20231005-115800.yaml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 1 addition & 4 deletions dbt/adapters/bigquery/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions tests/functional/adapter/constraints/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

_expected_sql_bigquery = """
create or replace table <model_identifier> (
id integer not null primary key not enforced references <foreign_key_model_identifier> (id) not enforced,
id INT64 not null primary key not enforced references <foreign_key_model_identifier> (id) not enforced,
color string,
date_day string
)
Expand Down Expand Up @@ -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 = """
{{
Expand Down Expand Up @@ -334,7 +331,7 @@ def models(self):
def expected_sql(self):
return """
create or replace table <model_identifier> (
id integer not null,
id INT64 not null,
color string,
date_day string,
primary key (id) not enforced,
Expand All @@ -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 <model_identifier> (
id integer not null,
id INT64 not null,
`from` string not null,
date_day string
)
Expand Down

0 comments on commit 5396aa0

Please sign in to comment.