0
0
dbtdata~30 mins

dbt-expectations for data quality - Mini Project: Build & Apply

Choose your learning style9 modes available
Data Quality Checks with dbt-expectations
📖 Scenario: You work as a data analyst in a retail company. You want to make sure the sales data you use is clean and reliable before making reports. Using dbt-expectations, you will add simple data quality tests to your sales data model.
🎯 Goal: Build a dbt model for sales data and add dbt-expectations tests to check for missing values and valid ranges. Finally, run the tests and see the results.
📋 What You'll Learn
Create a dbt model file with sample sales data
Configure the model to materialize as a table
Write dbt-expectations tests to check for nulls and valid sales amounts
Run the tests and print the test results
💡 Why This Matters
🌍 Real World
Data analysts and engineers use dbt-expectations to automate data quality checks and catch errors early in data pipelines.
💼 Career
Knowing how to write and run data quality tests with dbt-expectations is a valuable skill for data engineers and analytics engineers.
Progress0 / 4 steps
1
Create a dbt model with sample sales data
Create a dbt model file called sales.sql with a select statement that returns these exact rows: order_id 1, 2, 3; customer_id 101, 102, 103; and sales_amount 100, NULL, 250.
dbt
Need a hint?

Use a select * from (values ...) statement with the exact rows and column names.

2
Enable dbt-expectations in the model config
Add a config block at the top of sales.sql to set materialized to table.
dbt
Need a hint?

Use the {% config() %} Jinja block at the top of the model file.

3
Add dbt-expectations tests for data quality
Create a test file called test_sales.yml with dbt-expectations tests: one to check sales_amount has no nulls using expect_column_values_to_not_be_null, and one to check sales_amount values are between 0 and 1000 using expect_column_values_to_be_between.
dbt
Need a hint?

Use YAML format with models and tests keys. Add the two dbt-expectations tests exactly as shown.

4
Run dbt tests and print the results
Run dbt test --select sales in your terminal and print the summary line that shows how many tests passed and failed.
dbt
Need a hint?

Run the dbt test command and print the exact summary line showing test results.