Challenge - 5 Problems
Custom Singular Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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
Attempts:
2 left
💡 Hint
Think about what the SQL query is filtering for.
✗ Incorrect
The test selects rows where order_amount is less than zero, so it returns all such rows. This helps identify invalid negative amounts.
🧠 Conceptual
intermediate1:30remaining
Purpose of custom singular tests in dbt
What is the main purpose of creating a custom singular test in dbt?
Attempts:
2 left
💡 Hint
Think about whether the test checks rows or the whole dataset.
✗ Incorrect
Custom singular tests check conditions that apply to the entire dataset, such as ensuring no negative values exist anywhere.
🔧 Debug
advanced2: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
```
Attempts:
2 left
💡 Hint
Consider what a singular test expects as output.
✗ Incorrect
Singular tests can return a single row with an aggregate value. This query returns the count of customers with null emails, which is valid.
❓ data_output
advanced1: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?
Attempts:
2 left
💡 Hint
Think about what count(*) returns when no rows match.
✗ Incorrect
If no sales have a sale_date in the future, count(*) is zero, so the case returns 0.
🚀 Application
expert2: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?
Attempts:
2 left
💡 Hint
The test should return 0 if data is fresh, 1 if stale.
✗ Incorrect
Option A returns 0 if the latest update is within 24 hours, indicating fresh data, else 1 for stale data. This matches the test goal.