0
0
dbtdata~10 mins

dbt-utils package tests - Interactive Code Practice

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

Complete the code to use the dbt-utils test to check for duplicates in a column.

dbt
tests:
  - dbt_utils.unique_combination_of_columns:
      combination_of_columns: [[1]]
Drag options to blanks, or click blank then click option'
Acount
Bdate
Cid
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column that is not unique like 'count' or 'value'.
Forgetting to put the column name inside the list brackets.
2fill in blank
medium

Complete the code to use the dbt-utils test to check if a column has any null values.

dbt
tests:
  - dbt_utils.not_null:
      column_name: [1]
Drag options to blanks, or click blank then click option'
Astatus
Btotal
Cdate
Duser_id
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a column that can have nulls like 'status'.
Not specifying the column name correctly.
3fill in blank
hard

Fix the error in the dbt-utils test to check if two columns together are unique.

dbt
tests:
  - dbt_utils.unique_combination_of_columns:
      combination_of_columns: [[1]]
Drag options to blanks, or click blank then click option'
Auser_id, order_id
B['user_id', 'order_id']
Cuser_id
D'user_id', 'order_id'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the column names.
Not using a list format with brackets.
Using Python list syntax inside YAML incorrectly.
4fill in blank
hard

Fill both blanks to write a dbt-utils test that checks if values in a column exist in another table's column.

dbt
tests:
  - dbt_utils.relationships:
      to: [1]
      field: [2]
Drag options to blanks, or click blank then click option'
Aref('customers')
Bcustomer_id
Corder_id
Dref('orders')
Attempts:
3 left
💡 Hint
Common Mistakes
Using table names as strings instead of using ref().
Mixing up the 'to' and 'field' values.
5fill in blank
hard

Fill all three blanks to write a dbt-utils test that checks if a column's values are within a list of allowed values.

dbt
tests:
  - dbt_utils.accepted_values:
      column: [1]
      values: [[2]]
      quote_values: [3]
Drag options to blanks, or click blank then click option'
Astatus
B'active', 'inactive', 'pending'
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string values in the list.
Setting quote_values to false when values are strings.