-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from dwallace0723/add-cardinality-test
Add cardinality equality schema test
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{% macro test_cardinality_equality(model, from, to, field) %} | ||
|
||
with table_a as ( | ||
select | ||
{{ from }}, | ||
count(*) as num_rows | ||
from {{ model }} | ||
group by 1 | ||
), | ||
|
||
table_b as ( | ||
select | ||
{{ field }}, | ||
count(*) as num_rows | ||
from {{ to }} | ||
group by 1 | ||
), | ||
|
||
except_a as ( | ||
select * | ||
from table_a | ||
except | ||
select * | ||
from table_b | ||
), | ||
|
||
except_b as ( | ||
select * | ||
from table_b | ||
except | ||
select * | ||
from table_a | ||
), | ||
|
||
unioned as ( | ||
select * | ||
from except_a | ||
union all | ||
select * | ||
from except_b | ||
) | ||
|
||
select count(*) | ||
from unioned | ||
|
||
{% endmacro %} |