From 305f39b3011076d66ff0d90783f7962d9d8324cc Mon Sep 17 00:00:00 2001 From: sergisulca Date: Thu, 25 Apr 2024 17:22:35 -0300 Subject: [PATCH 1/2] add not_match_delete_condition --- .../materializations/models/incremental/incremental.sql | 2 ++ .../macros/materializations/models/incremental/merge.sql | 5 +++++ 2 files changed, 7 insertions(+) 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..6a4e1ee2 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 }}) From 4b27303176ef1aa91a5ee84e1ff08c99c4837529 Mon Sep 17 00:00:00 2001 From: sergisulca Date: Thu, 25 Apr 2024 17:59:33 -0300 Subject: [PATCH 2/2] drop () --- .../athena/macros/materializations/models/incremental/merge.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/include/athena/macros/materializations/models/incremental/merge.sql b/dbt/include/athena/macros/materializations/models/incremental/merge.sql index 6a4e1ee2..0a276ab8 100644 --- a/dbt/include/athena/macros/materializations/models/incremental/merge.sql +++ b/dbt/include/athena/macros/materializations/models/incremental/merge.sql @@ -137,7 +137,7 @@ {%- endfor %} {%- endif %} {% if not_match_delete_condition is not none -%} - when not matched and ({{ not_match_delete_condition }}) + when not matched and {{ not_match_delete_condition }} then delete {%- endif %} when not matched {% if insert_condition is not none -%} and {{ insert_condition }} {%- endif %}