Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Handy committed Jul 16, 2017
1 parent 4d42fc9 commit 948dd9b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target/
dbt_modules/
logs/
7 changes: 7 additions & 0 deletions dbt_project.yml
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"
68 changes: 68 additions & 0 deletions macros/equality.sql
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 %}

0 comments on commit 948dd9b

Please sign in to comment.