Skip to content

Commit

Permalink
Added optional parameter "union_strategy" and implemented it in all n…
Browse files Browse the repository at this point in the history
…h_link macros
  • Loading branch information
tkirschke committed Jan 13, 2025
1 parent c524a57 commit 72e0085
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions macros/tables/synapse/nh_link.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- macro synapse__nh_link(link_hashkey, foreign_hashkeys, payload, source_models, src_ldts, src_rsrc, disable_hwm, source_is_single_batch) -%}
{%- macro synapse__nh_link(link_hashkey, foreign_hashkeys, payload, source_models, src_ldts, src_rsrc, disable_hwm, source_is_single_batch, union_strategy) -%}

{%- set ns = namespace(last_cte= "", source_included_before = {}, has_rsrc_static_defined=true, source_models_rsrc_dict={}) -%}

Expand Down Expand Up @@ -26,6 +26,16 @@
{%- set ns.source_models_rsrc_dict = source_model_values['source_models_rsrc_dict'] -%}
{{ log('source_models: '~source_models, false) }}

{% if union_strategy|lower = 'all' %}
{% set union_command = 'UNION ALL' %}
{% elif union_strategy|lower == 'distinct' %}
{% set union_command = 'UNION' %}
{% else %}
{%- if execute -%}
{%- do exceptions.warn("[" ~ this ~ "] Warning: Parameter 'union_strategy' set to '" ~ union_strategy ~ "' which is not a supported choice. Set to 'all' or 'distinct' instead. UNION ALL is used now.") -%}
{% endif %}
{% set union_command = 'UNION ALL' %}
{% endif %}

{%- if not datavault4dbt.is_something(foreign_hashkeys) -%}
{%- set foreign_hashkeys = [] -%}
Expand Down Expand Up @@ -214,7 +224,7 @@ source_new_union AS (
FROM src_new_{{ source_number }}

{%- if not loop.last %}
UNION ALL
{{ union_command }}
{% endif -%}

{%- endfor -%}
Expand Down

0 comments on commit 72e0085

Please sign in to comment.