Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions macros/generic_tests/equal_rowcount.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{{ return('') }}
{% endif %}

{% if group_by_columns|length() > 0 %}
{% set has_grouping = group_by_columns|length() > 0 %}
{% if has_grouping %}
{% set select_gb_cols = group_by_columns|join(', ') + ', ' %}
{% set join_gb_cols %}
{% for c in group_by_columns %}
Expand All @@ -35,20 +36,25 @@ with a as (
1 as id_dbtutils_test_equal_rowcount,
count(*) as count_a
from {{ model }}
{{groupby_gb_cols}}

{% if has_grouping %}
{{groupby_gb_cols}}
{% endif %}

),

b as (

select
{{select_gb_cols}}
1 as id_dbtutils_test_equal_rowcount,
count(*) as count_b
from {{ compare_model }}
{{groupby_gb_cols}}
{% if has_grouping %}
{{groupby_gb_cols}}
{% endif %}

),

final as (

select
Expand All @@ -63,11 +69,14 @@ final as (
abs(count_a - count_b) as diff_count

from a
{% if has_grouping %}
full join b
on
a.id_dbtutils_test_equal_rowcount = b.id_dbtutils_test_equal_rowcount
{{join_gb_cols}}

{% else %}
cross join b
{% endif %}

)

Expand Down
Loading