expect_column_distinct_count_to_equal_other_table
How it Works
The expect_column_distinct_count_to_equal_other_table test from the dbt-expectations package verifies that the number of distinct values in a specified column matches the distinct count of a column in a reference table. This is useful for validating cross-table consistency — for example, ensuring that the number of unique customers in a fact table matches the number in the dimension table.
Steps and Conditions
- Column Selection: Identify the column to evaluate.
- Reference Table: Specify the comparison model and column.
- Execution: Both distinct counts are computed and compared.
- Outcome: Pass if the counts are equal; fail if they differ.
Example Usage: Data Warehouse
A data warehouse team wants to confirm that all customer IDs in the orders fact table have a corresponding entry in the dim_customers dimension table.
models:
- name: orders
columns:
- name: customer_id
tests:
- dbt_expectations.expect_column_distinct_count_to_equal_other_table:
compare_model: ref('dim_customers')
compare_column_name: customer_idA mismatch indicates that some customer IDs in orders lack dimension records, which would cause broken lookups in reporting.
Interested to Learn More? Try Out the Free 14-Days Trial
One AI-native workspace to build, ship, and monitor dbt™ — without the tool sprawl.
Join industry leaders winning with DinoAI agents
Data engineers and analysts at the most AI-native startups and enterprises use Paradime's DinoAI agents everyday to become market leaders.