Challenge - 5 Problems
dbt Unit Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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'
Attempts:
2 left
💡 Hint
Think about what a failing test returns in dbt.
✗ Incorrect
In dbt, tests return rows that fail the condition. Here, it returns all orders before 2020-01-01, so the output is those rows.
🧠 Conceptual
intermediate1:30remaining
Purpose of schema tests in dbt
What is the main purpose of schema tests in dbt?
Attempts:
2 left
💡 Hint
Think about what schema tests validate in your data.
✗ Incorrect
Schema tests in dbt check for data quality issues like uniqueness, null values, and referential integrity on columns.
🔧 Debug
advanced2: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 = nullAttempts:
2 left
💡 Hint
Remember how SQL treats comparisons with null.
✗ Incorrect
In SQL, 'user_id = null' always evaluates to false, so the query returns no rows but does not raise an error.
❓ data_output
advanced2:30remaining
Result of a custom dbt test with aggregation
Consider this custom dbt test SQL:
What does this test output?
select customer_id, count(*) as order_count from {{ ref('orders') }} group by customer_id having count(*) < 2What does this test output?
Attempts:
2 left
💡 Hint
Look at the HAVING clause and what it filters.
✗ Incorrect
The test returns customers who have less than 2 orders, showing those that fail the minimum order count condition.
🚀 Application
expert3: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?
Attempts:
2 left
💡 Hint
Think about how dbt tests foreign key relationships.
✗ Incorrect
The relationships test checks that every value in orders.customer_id exists in customers.id, enforcing referential integrity.