expect_column_distinct_count_to_equal
How it Works
The expect_column_distinct_count_to_equal test from the dbt-expectations package validates that the number of distinct values in a column equals exactly a specified count. This is more precise than range-based cardinality checks and is ideal for columns with a fixed, known set of categories where the exact count is controlled.
Steps and Conditions
- Column Selection: Identify the column to evaluate.
- Set Expected Count: Provide the exact expected distinct count using
value. - Execution: The distinct count is computed and compared to the expected value.
- Outcome: Pass if the counts match; fail if they differ.
Example Usage: Fixed Taxonomy
A content platform uses a fixed taxonomy of exactly 10 content categories. The distinct count of the category column should always be exactly 10.
models:
- name: content_items
columns:
- name: category
tests:
- dbt_expectations.expect_column_distinct_count_to_equal:
value: 10Any addition or removal of categories triggers the test failure, ensuring the taxonomy is managed through a controlled change process.
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.