From 0fb42901dd57bf80dbd3421b22ce00b2e9d7d19d Mon Sep 17 00:00:00 2001 From: mikaelene Date: Mon, 11 Jan 2021 14:58:07 +0100 Subject: [PATCH 1/3] This changes makes the macro easier to read and makes the code work for SQL Server without a custom adapter macro. Solved #3003 --- .../macros/materializations/snapshot/snapshot_merge.sql | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql b/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql index 74bfa2b32d3..9d97af510b5 100644 --- a/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql +++ b/core/dbt/include/global_project/macros/materializations/snapshot/snapshot_merge.sql @@ -13,13 +13,7 @@ when matched and DBT_INTERNAL_DEST.dbt_valid_to is null - and DBT_INTERNAL_SOURCE.dbt_change_type = 'update' - then update - set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to - - when matched - and DBT_INTERNAL_DEST.dbt_valid_to is null - and DBT_INTERNAL_SOURCE.dbt_change_type = 'delete' + and DBT_INTERNAL_SOURCE.dbt_change_type in ('update', 'delete') then update set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to From ccd20647224a360abb5dce8cee8c4182cf0b14c4 Mon Sep 17 00:00:00 2001 From: mikaelene Date: Mon, 11 Jan 2021 15:04:23 +0100 Subject: [PATCH 2/3] This changes makes the macro easier to read and makes the code work for SQL Server without a custom adapter macro. Solved #3003 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55ccd4a388c..fc0076fa913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ ## dbt 0.19.0 (Release TBD) ### Under the hood +- Rewrite macro for snapshot_merge_sql to make compatible with other SQL dialects ([#3003](https://github.com/fishtown-analytics/dbt/pull/3003) - Rewrite logic in `snapshot_check_strategy()` to make compatible with other SQL dialects ([#3000](https://github.com/fishtown-analytics/dbt/pull/3000), [#3001](https://github.com/fishtown-analytics/dbt/pull/3001)) Contributors: +- [@mikaelene](https://github.com/mikaelene) ([#3003](https://github.com/fishtown-analytics/dbt/pull/3003)) - [@dbeatty10](https://github.com/dbeatty10) ([dbt-adapter-tests#10](https://github.com/fishtown-analytics/dbt-adapter-tests/pull/10)) - [@swanderz](https://github.com/swanderz) ([#3000](https://github.com/fishtown-analytics/dbt/pull/3000)) From bc01572176b5f5adaf5c44233b2696c58671274f Mon Sep 17 00:00:00 2001 From: mikaelene Date: Mon, 11 Jan 2021 16:04:38 +0100 Subject: [PATCH 3/3] Sane as #3003. But for postgres --- .../postgres/macros/materializations/snapshot_merge.sql | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql b/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql index ba016c83a6a..807c70b6c02 100644 --- a/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql +++ b/plugins/postgres/dbt/include/postgres/macros/materializations/snapshot_merge.sql @@ -6,14 +6,7 @@ set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to from {{ source }} as DBT_INTERNAL_SOURCE where DBT_INTERNAL_SOURCE.dbt_scd_id::text = {{ target }}.dbt_scd_id::text - and DBT_INTERNAL_SOURCE.dbt_change_type::text = 'update'::text - and {{ target }}.dbt_valid_to is null; - - update {{ target }} - set dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to - from {{ source }} as DBT_INTERNAL_SOURCE - where DBT_INTERNAL_SOURCE.dbt_scd_id::text = {{ target }}.dbt_scd_id::text - and DBT_INTERNAL_SOURCE.dbt_change_type::text = 'delete'::text + and DBT_INTERNAL_SOURCE.dbt_change_type::text in ('update'::text, 'delete'::text) and {{ target }}.dbt_valid_to is null; insert into {{ target }} ({{ insert_cols_csv }})