-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tristan Handy
committed
Jul 16, 2017
1 parent
4d42fc9
commit 948dd9b
Showing
3 changed files
with
79 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
target/ | ||
dbt_modules/ | ||
logs/ |
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,7 @@ | ||
name: 'dbt_utils' | ||
version: '1.0' | ||
|
||
target-path: "target" | ||
clean-targets: ["target", "dbt_modules"] | ||
macro-paths: ['macros'] | ||
log-path: "logs" |
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,68 @@ | ||
{% macro test_equality(model, arg) %} | ||
|
||
|
||
|
||
-- setup | ||
|
||
{% set schema = model.split('.')[0] | replace('"', '') %} | ||
{% set model_a_name = model.split('.')[1] | replace('"', '') %} | ||
|
||
{% set dest_columns = adapter.get_columns_in_table(schema, model_a_name) %} | ||
{% set dest_cols_csv = dest_columns | map(attribute='quoted') | join(', ') %} | ||
|
||
|
||
|
||
-- core SQL | ||
|
||
with a as ( | ||
|
||
select * from {{ model }} | ||
|
||
), | ||
|
||
b as ( | ||
|
||
select * from {{ arg }} | ||
|
||
), | ||
|
||
a_minus_b as ( | ||
|
||
select {{dest_cols_csv}} from a | ||
except | ||
select {{dest_cols_csv}} from b | ||
|
||
), | ||
|
||
b_minus_a as ( | ||
|
||
select {{dest_cols_csv}} from b | ||
except | ||
select {{dest_cols_csv}} from a | ||
|
||
), | ||
|
||
unioned as ( | ||
|
||
select * from a_minus_b | ||
union all | ||
select * from b_minus_a | ||
|
||
), | ||
|
||
final as ( | ||
|
||
select (select count(*) from unioned) + | ||
(select abs( | ||
(select count(*) from a_minus_b) - | ||
(select count(*) from b_minus_a) | ||
)) | ||
as count | ||
|
||
) | ||
|
||
select count from final | ||
|
||
|
||
|
||
{% endmacro %} |