Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions integration_tests/models/generic_tests/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ seeds:
data_tests:
- dbt_utils.equality:
compare_model: ref('data_test_equality_a')
- dbt_utils.equality:
name: equality_test_with_where_clause
compare_model: |
(select 1 as col_a, 1 as col_b, 3 as col_c
union all
select 1 as col_a, 2 as col_b, 1 as col_c) compare_subquery
compare_columns:
- col_a
- col_b
- col_c
# NOTE: this 'where' syntax only works when we provide compare_columns and do not specify
# the precision parameter.
config:
where: col_a <> 2
- dbt_utils.equality:
compare_model: ref('data_test_equality_b')
error_if: "<1" #sneaky way to ensure that the test is returning failing rows
Expand Down
7 changes: 4 additions & 3 deletions macros/generic_tests/equality.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@



-- setup
{%- do dbt_utils._is_relation(model, 'test_equality') -%}

{# Ensure there are no extra columns in the compare_model vs model #}
{%- if not compare_columns -%}
{%- do dbt_utils._is_relation(model, 'test_equality') -%}
{%- do dbt_utils._is_ephemeral(model, 'test_equality') -%}
{%- do dbt_utils._is_relation(compare_model, 'test_equality') -%}
{%- do dbt_utils._is_ephemeral(compare_model, 'test_equality') -%}

{%- set model_columns = adapter.get_columns_in_relation(model) -%}
Expand Down Expand Up @@ -75,6 +74,7 @@
You cannot get the columns in an ephemeral model (due to not existing in the information schema),
so if the user does not provide an explicit list of columns we must error in the case it is ephemeral
#}
{%- do dbt_utils._is_relation(model, 'test_equality') -%}
{%- do dbt_utils._is_ephemeral(model, 'test_equality') -%}
{%- set compare_columns = adapter.get_columns_in_relation(model)-%}

Expand Down Expand Up @@ -102,6 +102,7 @@
{#-
If rounding is required, we need to get the types, so it cannot be ephemeral even if they provide column names
-#}
{%- do dbt_utils._is_relation(model, 'test_equality') -%}
{%- do dbt_utils._is_ephemeral(model, 'test_equality') -%}
{%- set columns = adapter.get_columns_in_relation(model) -%}

Expand Down
Loading