0
0
dbtdata~20 mins

Unit testing dbt models - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
dbt Unit Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a dbt test SQL query
Given this dbt test SQL model, what will be the output if the test fails?

select id from {{ ref('orders') }} where order_date < '2020-01-01'
dbt
select id from {{ ref('orders') }} where order_date < '2020-01-01'
AA count of rows instead of the actual rows
BAn empty table because dbt tests always return no rows
CA syntax error because of incorrect use of ref function
DA table with all order ids where order_date is before 2020-01-01
Attempts:
2 left
💡 Hint
Think about what a failing test returns in dbt.
🧠 Conceptual
intermediate
1:30remaining
Purpose of schema tests in dbt
What is the main purpose of schema tests in dbt?
ATo schedule dbt runs automatically
BTo check data quality by validating column values and constraints
CTo create new tables in the database
DTo run complex data transformations
Attempts:
2 left
💡 Hint
Think about what schema tests validate in your data.
🔧 Debug
advanced
2:00remaining
Identify the error in this dbt test SQL
This dbt test SQL is intended to check for nulls in the user_id column. What error will it raise?

select * from {{ ref('users') }} where user_id = null
ARuntime error because user_id column does not exist
BSyntaxError due to incorrect use of ref function
CNo error, but returns no rows because 'user_id = null' is always false
DReturns all rows because null comparison is ignored
Attempts:
2 left
💡 Hint
Remember how SQL treats comparisons with null.
data_output
advanced
2:30remaining
Result of a custom dbt test with aggregation
Consider this custom dbt test SQL:

select customer_id, count(*) as order_count from {{ ref('orders') }} group by customer_id having count(*) < 2

What does this test output?
ACustomers with fewer than 2 orders
BAll customers with their total order counts
CAn error because aggregation is not allowed in tests
DCustomers with exactly 2 orders
Attempts:
2 left
💡 Hint
Look at the HAVING clause and what it filters.
🚀 Application
expert
3:00remaining
Choosing the best test for referential integrity in dbt
You want to ensure that every order in the 'orders' model has a matching customer in the 'customers' model. Which dbt test should you use?
AA relationships test from orders.customer_id to customers.id
BA not_null test on orders.customer_id
CA uniqueness test on orders.customer_id
DA custom SQL test counting orders without customers
Attempts:
2 left
💡 Hint
Think about how dbt tests foreign key relationships.