0
0
dbtdata~20 mins

Generic tests with parameters in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Generic Test Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a generic test with a parameter
Given the following dbt generic test configuration, what will be the output when the test runs on a table with 3 null values in the email column?
dbt
version: 2
models:
  - name: users
    columns:
      - name: email
        tests:
          - not_null:
              severity: warn
              where: "email LIKE '%@example.com'"
AThe test will pass because the where clause filters out null emails.
BThe test will fail with 3 null values found in the filtered rows.
CThe test will fail with 0 null values because the where clause excludes all rows.
DThe test will error due to invalid syntax in the where clause.
Attempts:
2 left
💡 Hint
Think about how the where clause filters rows before checking for nulls.
🧠 Conceptual
intermediate
1:30remaining
Purpose of parameters in dbt generic tests
What is the main purpose of using parameters in dbt generic tests?
ATo customize test behavior like filtering rows or setting thresholds without writing new SQL.
BTo automatically generate documentation for tests.
CTo define new models dynamically during test execution.
DTo schedule tests to run at specific times.
Attempts:
2 left
💡 Hint
Parameters help change how tests work without changing the test code itself.
🔧 Debug
advanced
2:00remaining
Identify the error in this generic test with parameters
This dbt generic test is intended to check uniqueness on the user_id column but raises an error. What is the cause?
dbt
version: 2
models:
  - name: users
    columns:
      - name: user_id
        tests:
          - unique:
              where: "user_id != ''"
              threshold: 0
AThe 'threshold' parameter is not valid for the 'unique' test and causes an error.
BThe 'where' clause syntax is invalid and causes a SQL error.
CThe 'unique' test cannot be used on the 'user_id' column.
DThe test is missing a required 'severity' parameter.
Attempts:
2 left
💡 Hint
Check which parameters are supported by the 'unique' generic test.
data_output
advanced
2:00remaining
Result of a generic test with a threshold parameter
A generic test is configured to check that the number of nulls in the phone column is below a threshold of 2. The table has 3 null values in phone. What is the test result?
dbt
version: 2
models:
  - name: customers
    columns:
      - name: phone
        tests:
          - not_null:
              threshold: 2
ATest errors because 'threshold' is not a valid parameter for not_null.
BTest passes because threshold is ignored by not_null test.
CTest fails because 3 nulls exceed the threshold of 2.
DTest passes because threshold means minimum nulls allowed.
Attempts:
2 left
💡 Hint
Threshold sets the maximum allowed nulls before failing.
🚀 Application
expert
3:00remaining
Using multiple parameters in a generic test
You want to create a generic test that checks for duplicates in the order_id column but only for orders placed in 2023 and allow up to 5 duplicates before failing. Which configuration is correct?
A
tests:
  - unique:
      where: "order_date BETWEEN '2023-01-01' AND '2023-12-31'"
      threshold: 0
B
tests:
  - unique:
      where: "order_date >= '2023-01-01' AND order_date < '2024-01-01'"
      severity: error
C
tests:
  - unique:
      threshold: 5
      severity: warn
D
tests:
  - unique:
      where: "order_date >= '2023-01-01' AND order_date < '2024-01-01'"
      threshold: 5
Attempts:
2 left
💡 Hint
Combine filtering with threshold to allow some duplicates.