From e7786bf3f35b82ec7ae3a8955e82f327233d8ee5 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Wed, 31 May 2023 17:24:00 -0400 Subject: [PATCH 1/3] add sql_header tests for constraints --- dev-requirements.txt | 4 +- tests/functional/adapter/test_constraints.py | 52 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 0d914bd7e..4995aea48 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter +git+https://github.com/dbt-labs/dbt-core.git@7714/model-contracts-sql-header#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git@7714/model-contracts-sql-header#egg=dbt-tests-adapter&subdirectory=tests/adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor diff --git a/tests/functional/adapter/test_constraints.py b/tests/functional/adapter/test_constraints.py index 6b6189092..4a29fc861 100644 --- a/tests/functional/adapter/test_constraints.py +++ b/tests/functional/adapter/test_constraints.py @@ -3,6 +3,8 @@ BaseTableConstraintsColumnsEqual, BaseViewConstraintsColumnsEqual, BaseIncrementalConstraintsColumnsEqual, + BaseTableContractSqlHeader, + BaseIncrementalContractSqlHeader, BaseConstraintsRuntimeDdlEnforcement, BaseConstraintsRollback, BaseIncrementalConstraintsRuntimeDdlEnforcement, @@ -20,6 +22,7 @@ my_model_incremental_wrong_name_sql, model_schema_yml, constrained_model_schema_yml, + model_contract_header_schema_yml, ) _expected_sql_bigquery = """ @@ -45,6 +48,37 @@ # - 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") + + +my_model_contract_sql_header_sql = """ +{{ + config( + materialized = "table" + ) +}} + +{% call set_sql_header(config) %} +DECLARE DEMO STRING DEFAULT 'hello world'; +{% endcall %} + +SELECT DEMO as column_name +""" + +my_model_incremental_contract_sql_header_sql = """ +{{ + config( + materialized = "incremental", + on_schema_change="append_new_columns" + ) +}} + +{% call set_sql_header(config) %} +DECLARE DEMO STRING DEFAULT 'hello world'; +{% endcall %} + +SELECT DEMO as column_name +""" class BigQueryColumnEqualSetup: @@ -113,6 +147,24 @@ def models(self): } +class TestBigQueryTableContractsSqlHeader(BaseTableContractSqlHeader): + @pytest.fixture(scope="class") + def models(self): + return { + "my_model_contract_sql_header.sql": my_model_contract_sql_header_sql, + "constraints_schema.yml": model_contract_header_schema_yml, + } + + +class TestBigQueryIncrementalContractsSqlHeader(BaseIncrementalContractSqlHeader): + @pytest.fixture(scope="class") + def models(self): + return { + "my_model_contract_sql_header.sql": my_model_incremental_contract_sql_header_sql, + "constraints_schema.yml": model_contract_header_schema_yml, + } + + class TestBigQueryTableConstraintsRuntimeDdlEnforcement(BaseConstraintsRuntimeDdlEnforcement): @pytest.fixture(scope="class") def models(self): From 847f8aa68a588665a345ca38562c188fb9fbb58d Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 1 Jun 2023 12:04:39 -0400 Subject: [PATCH 2/3] changelog entry --- .changes/unreleased/Fixes-20230601-120430.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230601-120430.yaml diff --git a/.changes/unreleased/Fixes-20230601-120430.yaml b/.changes/unreleased/Fixes-20230601-120430.yaml new file mode 100644 index 000000000..715ac26a6 --- /dev/null +++ b/.changes/unreleased/Fixes-20230601-120430.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: test model constraints with sql headers +time: 2023-06-01T12:04:30.876751-04:00 +custom: + Author: michelleark + Issue: "7714" From 158c37fb2677e96c0bf968ed62a6eab70bb9d8a3 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Wed, 21 Jun 2023 17:13:53 -0400 Subject: [PATCH 3/3] revert dev-requirements.txt changes --- dev-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 4995aea48..0d914bd7e 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? -git+https://github.com/dbt-labs/dbt-core.git@7714/model-contracts-sql-header#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-core.git@7714/model-contracts-sql-header#egg=dbt-tests-adapter&subdirectory=tests/adapter +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor