forked from dbt-labs/dbt-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequal_rowcount.sql
More file actions
36 lines (24 loc) · 781 Bytes
/
equal_rowcount.sql
File metadata and controls
36 lines (24 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{% macro test_equal_rowcount(model) %}
{{ return(adapter.dispatch('test_equal_rowcount', packages = dbt_utils._get_utils_namespaces())(model, **kwargs)) }}
{% endmacro %}
{% macro default__test_equal_rowcount(model) %}
{% set compare_model = kwargs.get('compare_model', kwargs.get('arg')) %}
{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
{%- if not execute -%}
{{ return('') }}
{% endif %}
with a as (
select count(*) as count_a from {{ model }}
),
b as (
select count(*) as count_b from {{ compare_model }}
),
final as (
select abs(
(select count_a from a) -
(select count_b from b)
)
as diff_count
)
select diff_count from final
{% endmacro %}