Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use branch 8007-contract_type_aliasing #954

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we just be adding TEXT? Why delete the other types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point to types that are the same on both sides. They do nothing except (in some cases) change the type from lowercase to uppercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them in the dbt-core PR because they were causing unnecessary churning in the test cases.

"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