-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests Add accepted_range documentation Fixing invalid yaml in readme Add missing columns: entry Co-authored-by: Claire Carroll <carroll.claire.e@gmail.com> Update changelog
- Loading branch information
Showing
5 changed files
with
94 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
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
3 changes: 3 additions & 0 deletions
3
integration_tests/data/schema_tests/data_test_accepted_range.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,3 @@ | ||
id | ||
-1 | ||
11 |
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,32 @@ | ||
{% macro test_accepted_range(model, min_value = none, max_value = none, inclusive = true, where = "true") %} | ||
|
||
{%- set column_name = kwargs.get('column_name', kwargs.get('field')) -%} | ||
|
||
with meet_condition as( | ||
select {{ column_name }} | ||
from {{ model }} | ||
where {{ where }} | ||
), | ||
|
||
validation_errors as ( | ||
select * | ||
from meet_condition | ||
where | ||
-- never true, defaults to an empty result set. Exists to ensure any combo of the `or` clauses below succeeds | ||
1 = 2 | ||
|
||
{%- if min_value is not none %} | ||
-- records with a value >= min_value are permitted. The `not` flips this to find records that don't meet the rule. | ||
or not {{ column_name }} > {{- "=" if inclusive }} {{ min_value }} | ||
{%- endif %} | ||
|
||
{%- if max_value is not none %} | ||
-- records with a value <= max_value are permitted. The `not` flips this to find records that don't meet the rule. | ||
or not {{ column_name }} < {{- "=" if inclusive }} {{ max_value }} | ||
{%- endif %} | ||
) | ||
|
||
select count(*) | ||
from validation_errors | ||
|
||
{% endmacro %} |