From c2c1f761e8481434ca996cd1aefd25b266ebb329 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Tue, 1 Oct 2024 15:03:05 -0400 Subject: [PATCH] Update to use is_list filter --- .../materializations/snapshots/helpers.sql | 16 +++++++--------- .../materializations/snapshots/snapshot.sql | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/dbt/include/global_project/macros/materializations/snapshots/helpers.sql b/dbt/include/global_project/macros/materializations/snapshots/helpers.sql index 917054fe..169bdb64 100644 --- a/dbt/include/global_project/macros/materializations/snapshots/helpers.sql +++ b/dbt/include/global_project/macros/materializations/snapshots/helpers.sql @@ -50,14 +50,12 @@ snapshotted_data as ( select *, - {% if strategy.unique_key is iterable and strategy.unique_key is not string and strategy.unique_key is not mapping %} - {{ log("strategy.unique_key is list...." ~ strategy.unique_key, info=true) }} + {% if strategy.unique_key | is_list %} {% for key in strategy.unique_key %} {{ key }} as dbt_unique_key_{{ loop.index }} {%- if not loop.last %} , {%- endif %} {% endfor %} {% else %} - {{ log("strategy.unique_key is NOT list...." ~ strategy.unique_key, info=true) }} {{ strategy.unique_key }} as dbt_unique_key {% endif %} @@ -70,7 +68,7 @@ select *, - {% if strategy.unique_key is iterable and strategy.unique_key is not string and strategy.unique_key is not mapping %} + {% if strategy.unique_key | is_list %} {% for key in strategy.unique_key %} {{ key }} as dbt_unique_key_{{ loop.index }}, {% endfor %} @@ -89,7 +87,7 @@ select *, - {% if strategy.unique_key is iterable and strategy.unique_key is not string and strategy.unique_key is not mapping %} + {% if strategy.unique_key | is_list %} {% for key in strategy.unique_key %} {{ key }} as dbt_unique_key_{{ loop.index }}, {% endfor %} @@ -109,7 +107,7 @@ select *, - {% if strategy.unique_key is iterable and strategy.unique_key is not string and strategy.unique_key is not mapping %} + {% if strategy.unique_key | is_list %} {% for key in strategy.unique_key %} {{ key }} as dbt_unique_key_{{ loop.index }} {%- if not loop.last %} , {%- endif %} @@ -129,7 +127,7 @@ from insertions_source_data as source_data left outer join snapshotted_data on - {% if strategy.unique_key is iterable and strategy.unique_key is not string and strategy.unique_key is not mapping %} + {% if strategy.unique_key | is_list %} {% for key in strategy.unique_key %} snapshotted_data.dbt_unique_key_{{ loop.index }} = source_data.dbt_unique_key_{{ loop.index }} {%- if not loop.last %} and {%- endif %} @@ -163,7 +161,7 @@ from updates_source_data as source_data join snapshotted_data on - {% if strategy.unique_key is iterable and strategy.unique_key is not string and strategy.unique_key is not mapping %} + {% if strategy.unique_key | is_list %} {% for key in strategy.unique_key %} snapshotted_data.dbt_unique_key_{{ loop.index }} = source_data.dbt_unique_key_{{ loop.index }} {%- if not loop.last %} and {%- endif %} @@ -191,7 +189,7 @@ from snapshotted_data left join deletes_source_data as source_data on - {% if strategy.unique_key is iterable and strategy.unique_key is not string and strategy.unique_key is not mapping %} + {% if strategy.unique_key | is_list %} {% for key in strategy.unique_key %} snapshotted_data.dbt_unique_key_{{ loop.index }} = source_data.dbt_unique_key_{{ loop.index }} {%- if not loop.last %} and {%- endif %} diff --git a/dbt/include/global_project/macros/materializations/snapshots/snapshot.sql b/dbt/include/global_project/macros/materializations/snapshots/snapshot.sql index b383ffa7..0c9590b6 100644 --- a/dbt/include/global_project/macros/materializations/snapshots/snapshot.sql +++ b/dbt/include/global_project/macros/materializations/snapshots/snapshot.sql @@ -47,7 +47,7 @@ to_relation=target_relation) %} {% set remove_columns = ['dbt_change_type', 'DBT_CHANGE_TYPE', 'dbt_unique_key', 'DBT_UNIQUE_KEY'] %} - {% if unique_key is sequence and unique_key is not mapping and unique_key is not string %} + {% if unique_key | is_list %} {% for key in strategy.unique_key %} {{ remove_columns.append('dbt_unique_key_' + loop.index|string) }} {{ remove_columns.append('DBT_UNIQUE_KEY_' + loop.index|string) }}