-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add not_accepted_values schema test (#284)
Schema Test - Not accepted values, test fixed empty lines at the end Update changelog
- Loading branch information
1 parent
d4779ca
commit 0101a7e
Showing
5 changed files
with
66 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 %} |