From f066a8d5962b9033d6540868e1c86338301fdaa5 Mon Sep 17 00:00:00 2001 From: Pfitzn Date: Thu, 19 Sep 2024 14:59:13 +0200 Subject: [PATCH] Add built-in unique test if no preexisting test matches its name. --- models/marts/core/int_all_graph_resources.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/models/marts/core/int_all_graph_resources.sql b/models/marts/core/int_all_graph_resources.sql index d8a54f3f..1d3534c4 100644 --- a/models/marts/core/int_all_graph_resources.sql +++ b/models/marts/core/int_all_graph_resources.sql @@ -2,12 +2,16 @@ {# flatten the sets of permissable primary key test sets to one level for later iteration #} {%- set test_macro_list = [] %} +{%- set test_macro_names_list = [] %} {%- for test_set in var('primary_key_test_macros') -%} {%- for test in test_set %} - {%- do test_macro_list.append(test) -%} + {%- do test_macro_list.append(test) -%} {%- endfor %} {%- endfor -%} -{%- if test_macro_list | length == 0 -%} +{% for test in test_macro_list %} + {%- do test_macro_names_list.append(test.split('.')[1]) -%} +{%- endfor -%} +{%- if "test_unique" not in test_macro_names_list -%} {%- do test_macro_list.append("dbt.test_unique") -%} {%- endif -%} {%- set test_macro_set = set_strict(test_macro_list) -%}