Skip to content

Commit

Permalink
Refactor row count tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clausherther committed Nov 2, 2020
1 parent c6125e9 commit 4b92aa9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
partition_column=None,
partition_filter=None
) -%}
with row_count as (
select count(*) as cnt
from {{ model }}
{% if partition_column and partition_filter %}
where {{ partition_column }} {{ partition_filter }}
{% endif %}
)
select count(*)
from
row_count
where cnt < {{ minimum }} or
cnt > {{ maximum }}
{% set expression %}
count(*)
{% endset %}
{{ dbt_expectations.expression_between(model,
expression=expression,
minimum=minimum,
maximum=maximum,
partition_column=partition_column,
partition_filter=partition_filter
) }}
{%- endmacro -%}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
partition_column=None,
partition_filter=None
) -%}
select abs({{ expected_number_of_rows }} - count(*))
from {{ model }}
{% if partition_column and partition_filter %}
where {{ partition_column }} {{ partition_filter }}
{% endif %}
{% set filter_cond = partition_column ~ " " ~ partition_filter if partition_column and partition_filter else None %}
{% set expression %}
count(*) = {{ expected_number_of_rows }}
{% endset %}
{{ dbt_expectations.expression_is_true(model,
expression=expression,
filter_cond=filter_cond)
}}
{%- endmacro -%}

0 comments on commit 4b92aa9

Please sign in to comment.