expect_table_column_count_to_equal_other_table
How it Works
The expect_table_column_count_to_equal_other_table test from the dbt-expectations package validates that two tables have the same number of columns. This is useful for ensuring that a transformed model retains the same schema width as a source or reference table, guarding against silent column additions or removals.
Steps and Conditions
- Comparison Model: Specify the reference model using
compare_model. - Execution: The column counts of both tables are retrieved and compared.
- Outcome: Pass if the counts are equal; fail if they differ.
Example Usage: Staging Layer
A data team wants to ensure their stg_products model always has the same number of columns as the raw raw_products source, detecting any columns inadvertently added or dropped during transformation.
models:
- name: stg_products
tests:
- dbt_expectations.expect_table_column_count_to_equal_other_table:
compare_model: source('raw', 'products')Any schema divergence between staging and source is caught before it propagates to downstream models.
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.