Bird
Raised Fist0
dbtdata~10 mins

Generic tests with parameters in dbt - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a generic test that checks if a column has no null values.

dbt
version: 2
models:
  - name: users
    columns:
      - name: email
        tests:
          - not_null:
              [1]: true
Drag options to blanks, or click blank then click option'
Aseverity
Bconfig
Cparams
Denabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'params' instead of 'enabled' to activate the test.
Confusing 'severity' with enabling the test.
2fill in blank
medium

Complete the code to pass a parameter to a generic test that checks if values are greater than a threshold.

dbt
tests:
  - dbt_utils.expression_is_true:
      expression: "{{ column_name }} > {{ params.[1] }}"
Drag options to blanks, or click blank then click option'
Athreshold
Bvalue
Climit
Dmin_value
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' which is too generic.
Using 'limit' which is less common in dbt tests.
3fill in blank
hard

Fix the error in the generic test definition by completing the missing parameter name.

dbt
tests:
  - dbt_utils.unique_combination_of_columns:
      combination_of_columns: ["user_id", [1]]
Drag options to blanks, or click blank then click option'
Aemail
B"email"
C'email'
Demail_column
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around column names.
Using variable names instead of string literals.
4fill in blank
hard

Fill both blanks to create a generic test that checks if a column's values are within a list of allowed values.

dbt
tests:
  - dbt_utils.accepted_values:
      column_name: [1]
      values: [2]
Drag options to blanks, or click blank then click option'
A"status"
B["active", "inactive", "pending"]
C"state"
D["open", "closed"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes for column_name.
Not using a list for values.
5fill in blank
hard

Fill all three blanks to define a generic test with parameters for a column, a threshold, and a severity level.

dbt
tests:
  - dbt_utils.expression_is_true:
      expression: "{{ [1] }} > {{ params.[2] }}"
      severity: [3]
Drag options to blanks, or click blank then click option'
Acolumn_name
Bthreshold
C"ERROR"
D"WARNING"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names.
Not quoting the severity level.

Practice

(1/5)
1. What is the main benefit of using generic tests with parameters in dbt?
easy
A. They replace the need for SQL queries.
B. They automatically fix data errors.
C. They create new tables for each test.
D. They allow reusing test logic with different settings.

Solution

  1. Step 1: Understand generic tests

    Generic tests are reusable test templates that can be applied to many columns or tables.
  2. Step 2: Role of parameters

    Parameters customize these tests for specific columns or rules without rewriting the test logic.
  3. Final Answer:

    They allow reusing test logic with different settings. -> Option D
  4. Quick Check:

    Generic tests + parameters = reusable logic [OK]
Hint: Generic tests reuse logic; parameters customize them [OK]
Common Mistakes:
  • Thinking generic tests fix data automatically
  • Confusing generic tests with table creation
  • Believing generic tests replace SQL queries
2. Which of the following is the correct syntax to call a generic test with a parameter in dbt YAML?
easy
A. tests: - unique(column_name='id')
B. tests: - unique: { column_name: 'id' }
C. tests: - unique: id
D. tests: - unique: [id]

Solution

  1. Step 1: Review dbt test YAML syntax

    Generic tests with parameters are called using a dictionary format: test_name: {param: value}.
  2. Step 2: Match syntax to options

    tests: - unique: { column_name: 'id' } uses the correct dictionary format with the parameter inside curly braces.
  3. Final Answer:

    tests: - unique: { column_name: 'id' } -> Option B
  4. Quick Check:

    YAML test call = dictionary with parameters [OK]
Hint: Use dictionary syntax for parameters in YAML tests [OK]
Common Mistakes:
  • Using function call syntax in YAML
  • Passing parameters as plain strings or lists
  • Omitting curly braces for parameters
3. Given this dbt test YAML snippet:
tests:
- not_null:
column_name: 'email'
- accepted_values:
column_name: 'status'
values: ['active', 'inactive']

What does the accepted_values test check?
medium
A. It checks that 'status' column has only 'active' or 'inactive' values.
B. It checks that 'email' column is not null.
C. It checks that 'status' column has no null values.
D. It checks that 'email' column contains only 'active' or 'inactive'.

Solution

  1. Step 1: Identify the test and parameters

    The accepted_values test is applied to the 'status' column with allowed values ['active', 'inactive'].
  2. Step 2: Understand test purpose

    This test ensures the column only contains the specified allowed values.
  3. Final Answer:

    It checks that 'status' column has only 'active' or 'inactive' values. -> Option A
  4. Quick Check:

    accepted_values test = allowed values check [OK]
Hint: accepted_values limits column to listed values [OK]
Common Mistakes:
  • Confusing accepted_values with not_null test
  • Mixing columns between tests
  • Assuming accepted_values checks for nulls
4. You wrote this test in your dbt model YAML:
tests:
- unique:
column: 'user_id'

But the test fails to run. What is the likely error?
medium
A. Parameter name should be 'column_name', not 'column'.
B. The test 'unique' does not accept parameters.
C. The column name must be in double quotes, not single quotes.
D. The test should be under 'columns:', not 'tests:'.

Solution

  1. Step 1: Check parameter naming

    Generic tests expect parameter 'column_name' to specify the column, not 'column'.
  2. Step 2: Validate test structure

    Using 'column' instead of 'column_name' causes the test to fail because the parameter is unrecognized.
  3. Final Answer:

    Parameter name should be 'column_name', not 'column'. -> Option A
  4. Quick Check:

    Correct parameter name = column_name [OK]
Hint: Use exact parameter names like 'column_name' [OK]
Common Mistakes:
  • Using wrong parameter keys
  • Misplacing tests outside 'columns:' block
  • Confusing quote types for strings
5. You want to create a generic test that checks if a numeric column's values are within a custom range using parameters min_value and max_value. Which YAML snippet correctly calls this test for column age with range 18 to 65?
hard
A. tests: - within_range('age', 18, 65)
B. tests: - within_range: column: 'age' min: 18 max: 65
C. tests: - within_range: column_name: 'age' min_value: 18 max_value: 65
D. tests: - within_range: column_name: age min_value: '18' max_value: '65'

Solution

  1. Step 1: Use correct parameter names

    The test expects parameters named 'column_name', 'min_value', and 'max_value'.
  2. Step 2: Use correct YAML syntax and types

    tests: - within_range: column_name: 'age' min_value: 18 max_value: 65 uses correct parameter names and numeric values without quotes for numbers.
  3. Step 3: Check other options

    Function call syntax is invalid in YAML; incorrect parameter names like 'column', 'min', 'max'; unquoted column name and quoted numbers may cause type issues.
  4. Final Answer:

    tests: - within_range: column_name: 'age' min_value: 18 max_value: 65 -> Option C
  5. Quick Check:

    Correct params + types = tests: - within_range: column_name: 'age' min_value: 18 max_value: 65 [OK]
Hint: Match parameter names and use correct YAML types [OK]
Common Mistakes:
  • Using wrong parameter keys like 'column' or 'min'
  • Passing numbers as strings
  • Using function call syntax in YAML
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard