From 0cea63f020b8c3f10946f3ecf8bdda9bf5922fbe Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Wed, 26 Jun 2024 16:51:40 -0400 Subject: [PATCH 1/3] Skip "expand_target_column_types" if model has contract --- dbt/adapters/base/column.py | 3 --- .../materializations/models/incremental/incremental.sql | 9 ++++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dbt/adapters/base/column.py b/dbt/adapters/base/column.py index e2e6e1e0..195684a4 100644 --- a/dbt/adapters/base/column.py +++ b/dbt/adapters/base/column.py @@ -123,9 +123,6 @@ def numeric_type(cls, dtype: str, precision: Any, scale: Any) -> str: else: return "{}({},{})".format(dtype, precision, scale) - def __repr__(self) -> str: - return "".format(self.name, self.data_type) - @classmethod def from_description(cls, name: str, raw_data_type: str) -> "Column": match = re.match(r"([^(]+)(\([^)]+\))?", raw_data_type) diff --git a/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql b/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql index e8ff5c1e..5420287f 100644 --- a/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql +++ b/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql @@ -39,9 +39,12 @@ {% set need_swap = true %} {% else %} {% do run_query(get_create_table_as_sql(True, temp_relation, sql)) %} - {% do adapter.expand_target_column_types( - from_relation=temp_relation, - to_relation=target_relation) %} + {% set contract_config = config.get('contract') %} + {% if not contract_config.enforced %} + {% do adapter.expand_target_column_types( + from_relation=temp_relation, + to_relation=target_relation) %} + {% endif %} {#-- Process schema changes. Returns dict of changes if successful. Use source columns for upserting/merging --#} {% set dest_columns = process_schema_changes(on_schema_change, temp_relation, existing_relation) %} {% if not dest_columns %} From 738e210a68014fce578108a608c9dc721d3348ff Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Tue, 23 Jul 2024 16:55:51 -0400 Subject: [PATCH 2/3] Tweak check for existence of contract config --- .../macros/materializations/models/incremental/incremental.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql b/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql index 5420287f..f932751a 100644 --- a/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql +++ b/dbt/include/global_project/macros/materializations/models/incremental/incremental.sql @@ -40,7 +40,7 @@ {% else %} {% do run_query(get_create_table_as_sql(True, temp_relation, sql)) %} {% set contract_config = config.get('contract') %} - {% if not contract_config.enforced %} + {% if not contract_config or not contract_config.enforced %} {% do adapter.expand_target_column_types( from_relation=temp_relation, to_relation=target_relation) %} From 69a6ba55cc90686ca12ed231a68e38f6ef141efe Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Sun, 28 Jul 2024 22:10:36 -0400 Subject: [PATCH 3/3] Changie --- .changes/unreleased/Fixes-20240728-221030.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20240728-221030.yaml diff --git a/.changes/unreleased/Fixes-20240728-221030.yaml b/.changes/unreleased/Fixes-20240728-221030.yaml new file mode 100644 index 00000000..a1cddb24 --- /dev/null +++ b/.changes/unreleased/Fixes-20240728-221030.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Incremental table varchar column definition changed +time: 2024-07-28T22:10:30.673107-04:00 +custom: + Author: gshank + Issue: "276"