0
0
dbtdata~10 mins

Built-in tests (unique, not_null, accepted_values, relationships) in dbt - Interactive Code Practice

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

Complete the code to add a unique test on the 'id' column in a dbt model.

dbt
tests:
  - [1]:
      column_name: id
Drag options to blanks, or click blank then click option'
Aunique
Baccepted_values
Cnot_null
Drelationships
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'not_null' instead of 'unique' for uniqueness.
Forgetting to specify the column_name.
2fill in blank
medium

Complete the code to add a not_null test on the 'email' column in a dbt model.

dbt
tests:
  - [1]:
      column_name: email
Drag options to blanks, or click blank then click option'
Arelationships
Bunique
Caccepted_values
Dnot_null
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unique' when the goal is to check for nulls.
Not specifying the column_name correctly.
3fill in blank
hard

Fix the error in the accepted_values test to check that 'status' only contains 'active' or 'inactive'.

dbt
tests:
  - accepted_values:
      column_name: status
      values: [1]
Drag options to blanks, or click blank then click option'
A'active', 'inactive'
B['active', 'inactive']
Cactive, inactive
Dactive; inactive
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string without brackets instead of a list.
Separating values with commas but missing brackets.
4fill in blank
hard

Fill both blanks to create a relationships test linking 'user_id' in this model to 'id' in the 'users' model.

dbt
tests:
  - relationships:
      column_name: [1]
      to: ref('[2]')
      field: id
Drag options to blanks, or click blank then click option'
Auser_id
Border_id
Cusers
Dorders
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the column_name and the model name.
Not using ref() around the model name.
5fill in blank
hard

Fill all three blanks to add an accepted_values test on 'category' allowing only 'A', 'B', or 'C'.

dbt
tests:
  - accepted_values:
      column_name: [1]
      values: [[2], [3]]
Drag options to blanks, or click blank then click option'
Acategory
B'A'
C'B', 'C'
D'A', 'B', 'C'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting all values in one string instead of separate quoted strings.
Forgetting to quote the values.