forked from dbt-labs/dbt-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnot_accepted_values.sql
More file actions
37 lines (27 loc) · 792 Bytes
/
not_accepted_values.sql
File metadata and controls
37 lines (27 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{% test not_accepted_values(model, column_name, values, quote=True) %}
{{ return(adapter.dispatch('test_not_accepted_values', 'dbt_utils')(model, column_name, values, quote)) }}
{% endtest %}
{% macro default__test_not_accepted_values(model, column_name, values, quote=True) %}
with all_values as (
select distinct
{{ column_name }} as value_field
from {{ model }}
),
validation_errors as (
select
value_field
from all_values
where value_field in (
{% for value in values -%}
{% if quote -%}
'{{ value }}'
{%- else -%}
{{ value }}
{%- endif -%}
{%- if not loop.last -%},{%- endif %}
{%- endfor %}
)
)
select *
from validation_errors
{% endmacro %}