-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cardinality equality schema test #35
Changes from 5 commits
e552f18
925b937
f197e1a
755ef91
cacd6be
3b822d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{% macro test_cardinality_equality(model, from, to, field) %} | ||
|
||
with table_a as ( | ||
select | ||
{{ from }}, | ||
count(1) as num_rows | ||
from {{ model }} | ||
group by 1 | ||
), | ||
|
||
table_b as ( | ||
select | ||
{ field }}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a typo here |
||
count(1) 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 | ||
) | ||
|
||
select count(1) | ||
from ( | ||
select * | ||
from except_a | ||
union all | ||
select * | ||
from except_b | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you alias this subquery, then this schema test will also work on Postgres. At present, it errors out with:
So just change it to
and you should be good! Or, you could make another CTE for the subquery There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good catch. I just created an additional CTE for the subquery. |
||
|
||
{% endmacro %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dwallace0723 the
from
,to
, andfield
args can be named arbitrarily -- we used these for the referential integrity test, but you can pick other names if you'd like!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll probably just leave them as is. The current naming makes logical sense to me. LMK if you think there are more suitable arg names for this specific test.