-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from JavierMonton/schema_test/not_accepted_va…
…lues Schema test/not accepted values
- Loading branch information
Showing
5 changed files
with
67 additions
and
1 deletion.
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
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
5 changes: 5 additions & 0 deletions
5
integration_tests/data/schema_tests/data_test_not_accepted_values.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,5 @@ | ||
id,city | ||
1,Barcelona | ||
2,London | ||
3,Paris | ||
4,New York |
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,37 @@ | ||
{% macro test_not_accepted_values(model, values) %} | ||
|
||
{% set column_name = kwargs.get('column_name', kwargs.get('field')) %} | ||
{% set quote_values = kwargs.get('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_values -%} | ||
'{{ value }}' | ||
{%- else -%} | ||
{{ value }} | ||
{%- endif -%} | ||
{%- if not loop.last -%},{%- endif %} | ||
{%- endfor %} | ||
) | ||
|
||
) | ||
|
||
select count(*) as validation_errors | ||
from validation_errors | ||
|
||
{% endmacro %} |