Skip to content

Commit

Permalink
Avoid using nested {{ }}
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianburusdbt committed Dec 17, 2024
1 parent d582ab1 commit 8937201
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
{% do predicates.append(this_key_match) %}
{% endfor %}
{% else %}
{% set source_unique_key %}
DBT_INTERNAL_SOURCE.{{ unique_key }}
{% endset %}
{% set target_unique_key %}
DBT_INTERNAL_DEST.{{ unique_key }}
{% endset %}
{% set unique_key_match %}
{{ equals(DBT_INTERNAL_SOURCE.{{ unique_key }}, DBT_INTERNAL_DEST.{{ unique_key }}) }}
{{ equals(source_unique_key, target_unique_key) }}
{% endset %}
{% do predicates.append(unique_key_match) %}
{% endif %}
Expand Down Expand Up @@ -66,7 +72,14 @@
using {{ source }}
where (
{% for key in unique_key %}
{{ equals({{ source }}.{{ key }}, {{ target }}.{{ key }}) }}
{% set source_unique_key %}
{{ source }}.{{ key }}
{% endset %}
{% set target_unique_key %}
{{ target }}.{{ key }}
{% endset %}

{{ equals(source_unique_key, target_unique_key) }}
{{ "and " if not loop.last}}
{% endfor %}
{% if incremental_predicates %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@
from {{ target_relation }}
where
{% if config.get('dbt_valid_to_current') %}
{{ equals({{ columns.dbt_valid_to }}, {{ config.get('dbt_valid_to_current') }}) }}
{% set source_unique_key %}
columns.dbt_valid_to
{% endset %}
{% set target_unique_key %}
config.get('dbt_valid_to_current')
{% endset %}

{{ equals(source_unique_key, target_unique_key) }}
{% else %}
{{ columns.dbt_valid_to }} is null
{% endif %}
Expand Down Expand Up @@ -275,7 +282,14 @@
{% macro unique_key_join_on(unique_key, identifier, from_identifier) %}
{% if unique_key | is_list %}
{% for key in unique_key %}
{{ equals({{ identifier }}.dbt_unique_key_{{ loop.index }}, {{ from_identifier }}.dbt_unique_key_{{ loop.index }}) }}
{% set source_unique_key %}
{{ identifier }}.dbt_unique_key_{{ loop.index }}
{% endset %}
{% set target_unique_key %}
{{ from_identifier }}.dbt_unique_key_{{ loop.index }}
{% endset %}

{{ equals(source_unique_key, target_unique_key) }}
{%- if not loop.last %} and {%- endif %}
{% endfor %}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@

when matched
{% if config.get("dbt_valid_to_current") %}
and {{ equals(DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }}, {{ config.get('dbt_valid_to_current') }}) }}
{% set source_unique_key %}
DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }}
{% endset %}
{% set target_unique_key %}
{{ config.get('dbt_valid_to_current') }}
{% endset %}
and {{ equals(source_unique_key, target_unique_key) }}

{% else %}
and DBT_INTERNAL_DEST.{{ columns.dbt_valid_to }} is null
Expand Down

0 comments on commit 8937201

Please sign in to comment.