forked from kzzzr/mybi-dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_tests.sql
53 lines (33 loc) · 806 Bytes
/
schema_tests.sql
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- NON_EMPTY
{% macro test_not_empty(model, column_name) %}
with validation as (
select
count(1) as row_count
from {{ model }}
),
validation_errors as (
select
row_count
from validation
where row_count = 0
)
select count(*)
from validation_errors
{% endmacro %}
-- UNIQUE
{% macro default__test_unique(model) %}
{% set column_name = kwargs.get('column_name', kwargs.get('arg')) %}
select count(*) as validation_errors
from (
select
{{ column_name }} as a
from {{ model }}
where {{ column_name }} is not null
group by {{ column_name }}
having count(*) > 1
) validation_errors
{% endmacro %}
{% macro test_unique(model) %}
{% set macro = adapter.dispatch('test_unique') %}
{{ macro(model, **kwargs) }}
{% endmacro %}