What is the purpose of the dbt-utils package in dbt?
The dbt-utils package provides a collection of useful macros and tests that simplify common data transformation and testing tasks in dbt projects.
Click to reveal answer
beginner
Name one common test provided by dbt-utils and explain its use.
The unique_combination_of_columns test checks that the combination of specified columns in a model is unique, ensuring no duplicate rows based on those columns.
Click to reveal answer
intermediate
How do you add dbt-utils tests to your dbt project?
You add dbt-utils as a package in your packages.yml file, run dbt deps to install it, then reference its tests in your model's schema.yml file.
Click to reveal answer
beginner
What does the dbt_utils.not_null_proportion test check for?
It checks that the specified column(s) in a model have at least a minimum proportion of non-NULL values (e.g., 1.0 for no NULLs), ensuring data completeness.
Click to reveal answer
intermediate
Explain how the dbt_utils.expression_is_true test works.
This test runs a SQL expression you provide and checks that it evaluates to true for all rows in the model, allowing custom validation logic.
Click to reveal answer
Which file do you update to add dbt-utils as a dependency?
Aschema.yml
Bdbt_project.yml
Cprofiles.yml
Dpackages.yml
✗ Incorrect
The packages.yml file is used to declare external packages like dbt-utils.
What does the unique_combination_of_columns test ensure?
AThe combination of specified columns is unique
BColumns have unique values individually
CNo NULL values in columns
DColumns contain only numeric data
✗ Incorrect
It ensures that the combination of the specified columns does not have duplicate rows.
Which command installs the dbt-utils package after adding it to packages.yml?
Adbt deps
Bdbt run
Cdbt test
Ddbt compile
✗ Incorrect
dbt deps downloads and installs packages listed in packages.yml.
What does the not_null_proportion test check in dbt-utils?
AThat columns have unique values
BThat columns have default values
CThat columns do not contain NULL values
DThat columns contain only numbers
✗ Incorrect
The not_null_proportion test ensures no NULL values exist in the specified columns when the threshold is set to 1.0.
How do you specify a dbt-utils test in your model's schema.yml?
ABy writing SQL queries in the model file
BBy adding a <code>tests</code> section with the test name and arguments
CBy modifying <code>dbt_project.yml</code>
DBy running <code>dbt test</code> without configuration
✗ Incorrect
You add tests in schema.yml under the model's columns or at the model level with test names and parameters.
Describe the steps to add and use a dbt-utils test in your dbt project.
Think about package installation and test configuration.
You got /4 concepts.
Explain the difference between the not_null_proportion and unique_combination_of_columns tests in dbt-utils.
Focus on what each test validates about the data.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of using dbt-utils package tests in your data models?
easy
A. To write complex SQL queries faster
B. To speed up data loading processes
C. To check data quality by validating conditions like uniqueness and nulls
D. To create visual dashboards automatically
Solution
Step 1: Understand the role of dbt-utils tests
dbt-utils tests are designed to check data quality by validating conditions such as uniqueness, null values, and accepted values.
Step 2: Compare options with the purpose
Only To check data quality by validating conditions like uniqueness and nulls describes checking data quality, which matches the purpose of dbt-utils tests.
Final Answer:
To check data quality by validating conditions like uniqueness and nulls -> Option C
Quick Check:
dbt-utils tests = data quality checks [OK]
Hint: Tests in dbt-utils check data quality, not speed or visuals [OK]
Common Mistakes:
Thinking dbt-utils speeds up data loading
Confusing tests with dashboard creation
Assuming tests write SQL queries automatically
2. Which of the following is the correct syntax to add a uniqueness test using dbt-utils in a model YAML file?
easy
A. tests:
- dbt_utils.unique:
column_name: column_name
B. tests: - dbt_utils.unique: ['column_name']
C. tests: - dbt_utils.unique - column_name
D. tests: - dbt_utils.unique: {column_name}
Solution
Step 1: Recall dbt-utils test syntax in YAML
The correct syntax uses column_name parameter under the test, like dbt_utils.unique:
column_name: column_name.
But when running dbt test, it fails with an error. What is the likely problem?
medium
A. The column_name should be a string, not a list
B. The values parameter should be a list under accepted_values, not a key-value pair
C. The accepted_values test requires a where clause
D. The values list must be a string, not a list
Solution
Step 1: Review dbt-utils accepted_values test syntax
The accepted_values test expects column_name as a string identifier, not a list.
Step 2: Identify the YAML structure issue
column_name: ['status'] passes a list instead of string 'status', causing an error.
Final Answer:
The column_name should be a string, not a list -> Option A
Quick Check:
accepted_values column_name = string [OK]
Hint: column_name must be string for accepted_values test [OK]
Common Mistakes:
Passing column_name as list instead of string
Using string instead of list for values
Adding unnecessary where clause
5. You want to ensure a column email in your users model has no nulls and all values are unique using dbt-utils tests. Which YAML snippet correctly applies both tests?
hard
A. tests:
- dbt_utils.not_null:
email
- dbt_utils.unique:
email
B. tests:
- dbt_utils.not_null:
columns: ['email']
- dbt_utils.unique:
columns: ['email']
C. tests:
- dbt_utils.not_null:
- email
- dbt_utils.unique:
- email
D. tests:
- dbt_utils.not_null:
column_name: email
- dbt_utils.unique:
column_name: email
Solution
Step 1: Recall correct dbt-utils test syntax for columns
dbt-utils not_null and unique tests expect column_name: email under the test name.
Step 2: Evaluate each YAML snippet
Snippet with column_name: email for both tests correctly uses the required key-value format. The snippet missing colons after tests is invalid YAML. Using a list - email passes incorrect config type. Using columns is invalid key.