expect_column_values_to_be_of_type
How it Works
The expect_column_values_to_be_of_type test from the dbt-expectations package validates that a column's data type exactly matches the expected type. This is particularly important when integrating with downstream tools or APIs that require strict type contracts, or when validating that transformations haven't accidentally changed a column's type.
Steps and Conditions
- Column Selection: Identify the column to evaluate.
- Expected Type: Specify the exact data type using
column_type. - Execution: The actual column type is retrieved from the database metadata and compared.
- Outcome: Pass if the type matches; fail if it differs.
Example Usage: Analytics Engineering
An analytics engineer wants to ensure that the event_timestamp column in the web_events model always remains a TIMESTAMP type and hasn't been accidentally cast to VARCHAR during a refactor.
models:
- name: web_events
columns:
- name: event_timestamp
tests:
- dbt_expectations.expect_column_values_to_be_of_type:
column_type: timestampIf the column type changes, the test fails and prevents type-related issues from propagating to dashboards or ML pipelines.
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.