Skip to content

Commit

Permalink
Merge pull request #32 from nave91/feature/more-tests
Browse files Browse the repository at this point in the history
Test for columns with same value in all rows or no value at all
  • Loading branch information
drewbanin authored Nov 7, 2017
2 parents facf917 + 895c3e6 commit 191b433
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ model_name:
- ref('other_table_name')
```

#### at_least_one ([source](macros/schema_tests/at_least_one.sql))
This schema test asserts if column has at least one value.

Usage:
```
model_name:
constraints:
at_least_one:
- column_name
```

#### not_constant ([source](macros/schema_tests/not_constant.sql))
This schema test asserts if column does not have same value in all rows.

Usage:
```
model_name:
constraints:
not_constant:
- column_name
```

---
### SQL helpers
#### group_by ([source](macros/sql/groupby.sql))
Expand Down
15 changes: 15 additions & 0 deletions macros/schema_tests/at_least_one.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% macro test_at_least_one(model, arg) %}

select count(*)
from (
select

count({{ arg }})

from {{ model }}

having count({{ arg }}) = 0

) validation_errors

{% endmacro %}
18 changes: 18 additions & 0 deletions macros/schema_tests/not_constant.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

{% macro test_not_constant(model, arg) %}

select count(*)

from (

select
count(distinct {{ arg }})

from {{ model }}

having count(distinct {{ arg }}) = 1

) validation_errors


{% endmacro %}

0 comments on commit 191b433

Please sign in to comment.