-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: test_not_null_proportion support on athena (#19)
- Loading branch information
Showing
1 changed file
with
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% macro athena__test_not_null_proportion(model, group_by_columns) %} | ||
|
||
{% set column_name = kwargs.get('column_name', kwargs.get('arg')) %} | ||
{% set at_least = kwargs.get('at_least', kwargs.get('arg')) %} | ||
{% set at_most = kwargs.get('at_most', kwargs.get('arg', 1)) %} | ||
|
||
{% if group_by_columns|length() > 0 %} | ||
{% set select_gb_cols = group_by_columns|join(' ,') + ', ' %} | ||
{% set groupby_gb_cols = 'group by ' + group_by_columns|join(',') %} | ||
{% endif %} | ||
|
||
with validation as ( | ||
select | ||
{{select_gb_cols}} | ||
sum(case when {{ column_name }} is null then 0 else 1 end) / cast(count(*) as double) as not_null_proportion | ||
from {{ model }} | ||
{{groupby_gb_cols}} | ||
), | ||
validation_errors as ( | ||
select | ||
{{select_gb_cols}} | ||
not_null_proportion | ||
from validation | ||
where not_null_proportion < {{ at_least }} or not_null_proportion > {{ at_most }} | ||
) | ||
select | ||
* | ||
from validation_errors | ||
|
||
{% endmacro %} |