0
0
dbtdata~10 mins

dbt-expectations for data quality - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - dbt-expectations for data quality
Write dbt model SQL
Add dbt-expectations tests
Run dbt test command
dbt-expectations runs tests
Tests pass?
NoReport errors
Yes
Data quality confirmed
This flow shows how you add dbt-expectations tests to your dbt models, run tests, and check if data quality passes or errors are reported.
Execution Sample
dbt
select * from {{ ref('my_table') }}

-- Add test for no nulls in id
{{ expect_column_values_to_not_be_null('id') }}

-- Add test for unique ids
{{ expect_column_values_to_be_unique('id') }}
This code selects data from a table and adds two dbt-expectations tests: no nulls in 'id' column and unique values in 'id'.
Execution Table
StepActionTest RunResultNotes
1Run dbt testexpect_column_values_to_not_be_null('id')PassNo null values found in 'id' column
2Run dbt testexpect_column_values_to_be_unique('id')FailDuplicate values found in 'id' column
3Report errorsSummaryFailData quality test failed due to duplicates
4Fix data or modelN/AN/AUser updates data or model to fix duplicates
5Re-run dbt testAll testsPassAll data quality tests pass
💡 Tests stop when all pass or errors are reported for fixing
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 5
id column null checkNot runPassPassPass
id column uniquenessNot runNot runFailPass
data quality statusUnknownUnknownFailPass
Key Moments - 2 Insights
Why does the uniqueness test fail even if the null check passes?
Because null values and duplicates are different issues. The null check (row 1) passes since no nulls exist, but duplicates cause the uniqueness test (row 2) to fail.
What happens after a test fails?
The failure is reported (row 3), and you need to fix the data or model before re-running tests (rows 4 and 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of the null check test at step 1?
ANot run
BFail
CPass
DError
💡 Hint
Check the 'Result' column in row 1 of the execution table.
At which step does the uniqueness test fail?
AStep 1
BStep 2
CStep 3
DStep 5
💡 Hint
Look at the 'Test Run' and 'Result' columns in the execution table rows.
If the duplicates were fixed before step 5, what would be the data quality status after step 5?
APass
BFail
CUnknown
DError
💡 Hint
Refer to the 'data quality status' variable in the variable tracker after step 5.
Concept Snapshot
dbt-expectations adds data quality tests to dbt models.
Write tests like expect_column_values_to_not_be_null or expect_column_values_to_be_unique.
Run tests with 'dbt test' command.
Tests pass or fail based on data.
Fix data if tests fail and re-run.
Ensures reliable, clean data in your warehouse.
Full Transcript
This visual execution shows how dbt-expectations helps check data quality in dbt projects. First, you write your dbt model SQL. Then, you add dbt-expectations tests to check things like no nulls or unique values in columns. When you run 'dbt test', these tests run on your data. If tests pass, data quality is confirmed. If tests fail, errors are reported so you can fix data or models. After fixing, you re-run tests until all pass. The execution table traces each test step, showing pass or fail results. The variable tracker shows how test results change over time. Key moments clarify why some tests fail while others pass and what to do next. The quiz checks your understanding of test results and flow. This process helps keep your data clean and trustworthy.