From 55dda7ea43503308a630042889b415d3137cf4a1 Mon Sep 17 00:00:00 2001 From: Peter Allen Webb Date: Thu, 19 Dec 2024 10:13:42 -0500 Subject: [PATCH] Revert original fix which is no longer needed. Add a slightly-paranoid check to minimize any chance of regressions. --- .../macros/materializations/snapshots/helpers.sql | 4 +++- .../macros/materializations/snapshots/snapshot_merge.sql | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dbt/include/global_project/macros/materializations/snapshots/helpers.sql b/dbt/include/global_project/macros/materializations/snapshots/helpers.sql index 6454877c..6e7e20ae 100644 --- a/dbt/include/global_project/macros/materializations/snapshots/helpers.sql +++ b/dbt/include/global_project/macros/materializations/snapshots/helpers.sql @@ -40,7 +40,9 @@ {% macro default__snapshot_staging_table(strategy, source_sql, target_relation) -%} {% set columns = config.get('snapshot_table_column_names') or get_snapshot_table_column_names() %} - {% set new_scd_id = snapshot_hash_arguments([columns.dbt_scd_id, snapshot_get_time()]) %} + {% if strategy.hard_deletes == 'new_record' %} + {% set new_scd_id = snapshot_hash_arguments([columns.dbt_scd_id, snapshot_get_time()]) %} + {% endif %} with snapshot_query as ( {{ source_sql }} diff --git a/dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql b/dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql index 51773a71..cf787e4f 100644 --- a/dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql +++ b/dbt/include/global_project/macros/materializations/snapshots/snapshot_merge.sql @@ -11,7 +11,7 @@ merge into {{ target.render() }} as DBT_INTERNAL_DEST using {{ source }} as DBT_INTERNAL_SOURCE - on DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }} = DBT_INTERNAL_DEST.{{ columns.dbt_scd_id }} and DBT_INTERNAL_SOURCE.dbt_change_type != 'insert' + on DBT_INTERNAL_SOURCE.{{ columns.dbt_scd_id }} = DBT_INTERNAL_DEST.{{ columns.dbt_scd_id }} when matched {% if config.get("dbt_valid_to_current") %}