From 2bfde1e4f20113782e804a95f40d1933a525a2c0 Mon Sep 17 00:00:00 2001 From: Christophe Oudar Date: Sun, 31 Oct 2021 02:28:19 +0200 Subject: [PATCH] Use common columns for incremental schema changes --- CHANGELOG.md | 3 ++- .../snowflake/macros/materializations/incremental.sql | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0c52f49e..191ab4d49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ N/A ### Fixes -N/A +- When on_schema_change is set, pass common columns as dest_columns in incremental merge macros ([#4144](https://github.com/dbt-labs/dbt-core/issues/4144)) ### Under the hood - Add optional profile parameters for atypical local connection setups ([#21](https://github.com/dbt-labs/dbt-snowflake/issues/21), [#36](https://github.com/dbt-labs/dbt-snowflake/pull/36)) @@ -19,6 +19,7 @@ N/A ### Contributors - [@NiallRees](https://github.com/NiallRees) ([#32](https://github.com/dbt-labs/dbt-snowflake/pull/32)) +- [@Kayrnt](https://github.com/Kayrnt) ([38](https://github.com/dbt-labs/dbt-snowflake/pull/38)) ## dbt-snowflake v1.0.0b1 (October 11, 2021) diff --git a/dbt/include/snowflake/macros/materializations/incremental.sql b/dbt/include/snowflake/macros/materializations/incremental.sql index 8c49ec5f0..edc665e83 100644 --- a/dbt/include/snowflake/macros/materializations/incremental.sql +++ b/dbt/include/snowflake/macros/materializations/incremental.sql @@ -58,8 +58,9 @@ {% do adapter.expand_target_column_types( from_relation=tmp_relation, to_relation=target_relation) %} - {% do process_schema_changes(on_schema_change, tmp_relation, existing_relation) %} - {% set dest_columns = adapter.get_columns_in_relation(existing_relation) %} + {% set schema_changes_dict = process_schema_changes(on_schema_change, tmp_relation, existing_relation) %} + {#-- Destination columns is the intersection of source and target table --#} + {% set dest_columns = schema_changes_dict.get('in_target_and_source', existing_columns) %} {% set build_sql = dbt_snowflake_get_incremental_sql(strategy, tmp_relation, target_relation, unique_key, dest_columns) %} {% endif %}