Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions dbt_unit_test/templates/diff_macro.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
{% macro test_diff(model, test) %}
with extra_rows as (
SELECT * FROM {{ model }} EXCEPT SELECT * FROM {{ test }}
),
missing_rows as (
SELECT * FROM {{ test }} EXCEPT SELECT * FROM {{ model }}
)
SELECT count(*)
FROM (SELECT * FROM extra_rows UNION ALL SELECT * FROM missing_rows) a
{{ return(adapter.dispatch('test_diff')(model, test)) }}
{% endmacro %}

{% macro default__test_diff(model, test) %}
with extra_rows as (
SELECT * FROM {{ model }} EXCEPT SELECT * FROM {{ test }}
),
missing_rows as (
SELECT * FROM {{ test }} EXCEPT SELECT * FROM {{ model }}
)
SELECT count(*)
FROM (SELECT * FROM extra_rows UNION ALL SELECT * FROM missing_rows) a
{% endmacro %}

{% macro bigquery__test_diff(model, test) %}
WITH extra_rows AS (
SELECT * FROM {{ model }} EXCEPT DISTINCT SELECT * FROM {{ test }}
),
missing_rows AS (
SELECT * FROM {{ test }} EXCEPT DISTINCT SELECT * FROM {{ model }}
),
all_missing as (
SELECT COUNT(*) AS missing_count
FROM (SELECT * FROM extra_rows UNION ALL SELECT * FROM missing_rows) a
)
SELECT missing_count FROM all_missing
WHERE missing_count > 0
{% endmacro %}