From 8bb8cefb2babd0749867e1c71f00d84f9764ff6b Mon Sep 17 00:00:00 2001 From: Joel Labes Date: Sat, 17 Apr 2021 06:38:56 +1200 Subject: [PATCH] Fix cardinality test error (#334) --- CHANGELOG.md | 2 +- .../schema_tests/data_cardinality_equality_a.csv | 4 ++++ .../schema_tests/data_cardinality_equality_b.csv | 4 ++++ integration_tests/models/schema_tests/schema.yml | 13 +++++++++++++ macros/schema_tests/cardinality_equality.sql | 2 +- 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 integration_tests/data/schema_tests/data_cardinality_equality_a.csv create mode 100644 integration_tests/data/schema_tests/data_cardinality_equality_b.csv diff --git a/CHANGELOG.md b/CHANGELOG.md index f34ce774..a2deabbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,10 @@ ## Fixes * Handle booleans gracefully in the unpivot macro ([#305](https://github.com/fishtown-analytics/dbt-utils/pull/305) [@avishalom](https://github.com/avishalom)) * Fix a bug in `get_relation_by_prefix` that happens with Snowflake external tables. Now the macro will retrieve tables that match the prefix which are external tables ([#350](https://github.com/fishtown-analytics/dbt-utils/issues/350)) +* Fix `cardinality_equality` test when the two tables' column names differed ([#334](https://github.com/fishtown-analytics/dbt-utils/pull/334)) [@joellabes](https://github.com/joellabes) ## Under the hood - # dbt-utils v0.6.4 ### Fixes diff --git a/integration_tests/data/schema_tests/data_cardinality_equality_a.csv b/integration_tests/data/schema_tests/data_cardinality_equality_a.csv new file mode 100644 index 00000000..ad9cdeb5 --- /dev/null +++ b/integration_tests/data/schema_tests/data_cardinality_equality_a.csv @@ -0,0 +1,4 @@ +same_name +1 +2 +3 \ No newline at end of file diff --git a/integration_tests/data/schema_tests/data_cardinality_equality_b.csv b/integration_tests/data/schema_tests/data_cardinality_equality_b.csv new file mode 100644 index 00000000..dfca57d6 --- /dev/null +++ b/integration_tests/data/schema_tests/data_cardinality_equality_b.csv @@ -0,0 +1,4 @@ +same_name,different_name +1,2 +2,3 +3,1 \ No newline at end of file diff --git a/integration_tests/models/schema_tests/schema.yml b/integration_tests/models/schema_tests/schema.yml index 44d6b296..885586a9 100644 --- a/integration_tests/models/schema_tests/schema.yml +++ b/integration_tests/models/schema_tests/schema.yml @@ -126,6 +126,18 @@ models: combination_of_columns: - month - product + + - name: data_cardinality_equality_a + columns: + - name: same_name + tests: + - dbt_utils.cardinality_equality: + to: ref('data_cardinality_equality_b') + field: same_name + - dbt_utils.cardinality_equality: + to: ref('data_cardinality_equality_b') + field: different_name + - name: data_test_accepted_range columns: @@ -145,3 +157,4 @@ models: min_value: 0 inclusive: true where: "id <> -1" + diff --git a/macros/schema_tests/cardinality_equality.sql b/macros/schema_tests/cardinality_equality.sql index 3879c317..c6923685 100644 --- a/macros/schema_tests/cardinality_equality.sql +++ b/macros/schema_tests/cardinality_equality.sql @@ -25,7 +25,7 @@ select {{ field }}, count(*) as num_rows from {{ to }} -group by {{ column_name }} +group by {{ field }} ), except_a as (