Skip to content

Commit 191b433

Browse files
authored
Merge pull request #32 from nave91/feature/more-tests
Test for columns with same value in all rows or no value at all
2 parents facf917 + 895c3e6 commit 191b433

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ model_name:
7272
- ref('other_table_name')
7373
7474
```
75+
76+
#### at_least_one ([source](macros/schema_tests/at_least_one.sql))
77+
This schema test asserts if column has at least one value.
78+
79+
Usage:
80+
```
81+
model_name:
82+
constraints:
83+
at_least_one:
84+
- column_name
85+
86+
```
87+
88+
#### not_constant ([source](macros/schema_tests/not_constant.sql))
89+
This schema test asserts if column does not have same value in all rows.
90+
91+
Usage:
92+
```
93+
model_name:
94+
constraints:
95+
not_constant:
96+
- column_name
97+
98+
```
99+
75100
---
76101
### SQL helpers
77102
#### group_by ([source](macros/sql/groupby.sql))

macros/schema_tests/at_least_one.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% macro test_at_least_one(model, arg) %}
2+
3+
select count(*)
4+
from (
5+
select
6+
7+
count({{ arg }})
8+
9+
from {{ model }}
10+
11+
having count({{ arg }}) = 0
12+
13+
) validation_errors
14+
15+
{% endmacro %}

macros/schema_tests/not_constant.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
{% macro test_not_constant(model, arg) %}
3+
4+
select count(*)
5+
6+
from (
7+
8+
select
9+
count(distinct {{ arg }})
10+
11+
from {{ model }}
12+
13+
having count(distinct {{ arg }}) = 1
14+
15+
) validation_errors
16+
17+
18+
{% endmacro %}

0 commit comments

Comments
 (0)