0
0
dbtdata~20 mins

Custom singular tests in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Singular Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple custom singular test in dbt
Given the following dbt custom singular test code, what will be the output when the test is run?
dbt
select * from {{ ref('orders') }} where order_amount < 0
AReturns no rows because order_amount cannot be negative
BReturns all rows from 'orders' where order_amount is positive
CRaises a compilation error due to invalid syntax
DReturns all rows from 'orders' where order_amount is negative
Attempts:
2 left
💡 Hint
Think about what the SQL query is filtering for.
🧠 Conceptual
intermediate
1:30remaining
Purpose of custom singular tests in dbt
What is the main purpose of creating a custom singular test in dbt?
ATo check a condition that applies to the entire table or dataset as a whole
BTo validate individual rows based on column values
CTo generate documentation for models automatically
DTo create new tables from existing data
Attempts:
2 left
💡 Hint
Think about whether the test checks rows or the whole dataset.
🔧 Debug
advanced
2:00remaining
Identify the error in this custom singular test
What error will occur when running this custom singular test in dbt? ```sql select count(*) from {{ ref('customers') }} where email is null ```
ACompilation error because the test must return rows, not an aggregate
BNo error; test runs and returns count of customers with null email
CRuntime error due to missing table 'customers'
DSyntax error because 'count(*)' is not allowed in singular tests
Attempts:
2 left
💡 Hint
Consider what a singular test expects as output.
data_output
advanced
1:30remaining
Result of a custom singular test with a condition
Consider this custom singular test SQL: ```sql select case when count(*) = 0 then 0 else 1 end as test_result from {{ ref('sales') }} where sale_date > current_date ``` What will be the value of 'test_result' if there are no future sales?
ANULL
B1
C0
DRaises an error because current_date is invalid
Attempts:
2 left
💡 Hint
Think about what count(*) returns when no rows match.
🚀 Application
expert
2:30remaining
Designing a custom singular test for data freshness
You want to create a custom singular test in dbt to check if the latest update timestamp in your 'events' table is within the last 24 hours. Which SQL query correctly implements this test?
Aselect case when max(updated_at) >= current_timestamp - interval '1 day' then 0 else 1 end as freshness_test from {{ ref('events') }}
Bselect * from {{ ref('events') }} where updated_at < current_timestamp - interval '1 day'
Cselect count(*) from {{ ref('events') }} where updated_at > current_timestamp + interval '1 day'
Dselect case when min(updated_at) <= current_timestamp + interval '1 day' then 1 else 0 end as freshness_test from {{ ref('events') }}
Attempts:
2 left
💡 Hint
The test should return 0 if data is fresh, 1 if stale.