-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unique_combination_of_columns test (#177)
- Loading branch information
Claire Carroll
authored
Dec 11, 2019
1 parent
18ab2fb
commit 21a0b96
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
integration_tests/data/schema_tests/data_unique_combination_of_columns.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
month,product,revenue | ||
2019-01-01,jaffle,500 | ||
2019-01-01,lamington,100 | ||
2019-01-01,pavlova,600 | ||
2019-02-01,jaffle,300 | ||
2019-02-01,lamington,300 | ||
2019-02-01,pavlova,400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% macro test_unique_combination_of_columns(model) %} | ||
|
||
{%- set columns = kwargs.get('combination_of_columns', kwargs.get('arg')) %} | ||
|
||
{%- set columns_csv=columns | join(', ') %} | ||
|
||
with validation_errors as ( | ||
|
||
select | ||
{{ columns_csv }} | ||
from {{ model }} | ||
|
||
group by {{ columns_csv }} | ||
having count(*) > 1 | ||
|
||
) | ||
|
||
select count(*) | ||
from validation_errors | ||
|
||
|
||
{% endmacro %} |