expect_table_column_count_to_equal
How it Works
The expect_table_column_count_to_equal test from the dbt-expectations package validates that a table has exactly the number of columns specified. This is a stricter variant of expect_table_column_count_to_be_between and is suitable for tables with a tightly defined, fixed schema.
Steps and Conditions
- Set Expected Count: Provide the exact column count using
value. - Execution: The actual column count is retrieved from schema metadata and compared.
- Outcome: Pass if the counts match exactly; fail if they differ.
Example Usage: Contract-Bound Data
A data team exports a contract_data model to a partner via API. The contract specifies exactly 12 fields. Any schema change that adds or removes a column must be flagged.
models:
- name: contract_data
tests:
- dbt_expectations.expect_table_column_count_to_equal:
value: 12Any deviation from 12 columns will fail the test and prevent a breaking schema change from being deployed to the partner API.
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.