Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added incremental predicates to Snowflakes tables #198

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion macros/tables/snowflake/hub.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

{%- set source_cols = automate_dv.expand_column_list(columns=[src_pk, src_nk, src_extra_columns, src_ldts, src_source]) -%}

{%- set predicates = model.config.get('predicates', none) -%}

{%- if model.config.materialized == 'vault_insert_by_rank' %}
{%- set source_cols_with_rank = source_cols + [config.get('rank_column')] -%}
{%- endif %}
Expand Down Expand Up @@ -106,8 +108,13 @@ records_to_insert AS (
{%- if automate_dv.is_any_incremental() %}
LEFT JOIN {{ this }} AS d
ON {{ automate_dv.multikey(src_pk, prefix=['a','d'], condition='=') }}
{%- if predicates is not none %}
{% for predicate in predicates %}
AND d.{{ predicate }}
{% endfor %}
{% endif %}
WHERE {{ automate_dv.multikey(src_pk, prefix='d', condition='IS NULL') }}
{%- endif %}
{%- endif %}
)

SELECT * FROM records_to_insert
Expand Down
7 changes: 7 additions & 0 deletions macros/tables/snowflake/sat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{%- set window_cols = automate_dv.expand_column_list(columns=[src_pk, src_hashdiff, src_ldts]) -%}
{%- set pk_cols = automate_dv.expand_column_list(columns=[src_pk]) -%}
{%- set enable_ghost_record = var('enable_ghost_records', false) -%}
{%- set predicates = model.config.get('predicates', none) -%}

{%- if model.config.materialized == 'vault_insert_by_rank' %}
{%- set source_cols_with_rank = source_cols + [config.get('rank_column')] -%}
Expand Down Expand Up @@ -65,6 +66,12 @@ latest_records AS (
FROM source_data
) AS source_records
ON {{ automate_dv.multikey(src_pk, prefix=['current_records','source_records'], condition='=') }}
WHERE 1=1
{%- if predicates is not none %}
{% for predicate in predicates %}
AND {{ predicate }}
{% endfor %}
{% endif %}
) AS a
WHERE a.rank = 1
),
Expand Down