diff --git a/dbt/include/athena/macros/materializations/models/incremental/incremental.sql b/dbt/include/athena/macros/materializations/models/incremental/incremental.sql index 61074f10..b8e9afd2 100644 --- a/dbt/include/athena/macros/materializations/models/incremental/incremental.sql +++ b/dbt/include/athena/macros/materializations/models/incremental/incremental.sql @@ -79,6 +79,7 @@ {% set unique_key = config.get('unique_key') %} {% set incremental_predicates = config.get('incremental_predicates') %} {% set delete_condition = config.get('delete_condition') %} + {% set not_match_delete_condition = config.get('not_match_delete_condition') %} {% set update_condition = config.get('update_condition') %} {% set insert_condition = config.get('insert_condition') %} {% set empty_unique_key -%} @@ -115,6 +116,7 @@ update_condition=update_condition, insert_condition=insert_condition, force_batch=force_batch, + not_match_delete_condition=not_match_delete_condition ) %} {% do to_drop.append(tmp_relation) %} diff --git a/dbt/include/athena/macros/materializations/models/incremental/merge.sql b/dbt/include/athena/macros/materializations/models/incremental/merge.sql index 8741adb7..0a276ab8 100644 --- a/dbt/include/athena/macros/materializations/models/incremental/merge.sql +++ b/dbt/include/athena/macros/materializations/models/incremental/merge.sql @@ -77,6 +77,7 @@ update_condition, insert_condition, force_batch, + not_match_delete_condition, statement_name="main" ) %} @@ -135,6 +136,10 @@ {%- endif -%} {%- endfor %} {%- endif %} + {% if not_match_delete_condition is not none -%} + when not matched and {{ not_match_delete_condition }} + then delete + {%- endif %} when not matched {% if insert_condition is not none -%} and {{ insert_condition }} {%- endif %} then insert ({{ dest_cols_csv }}) values ({{ src_cols_csv }})