Test severity levels in dbt - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When using test severity levels in dbt, it's important to understand how the number of tests affects the time it takes to run them.
We want to know how the execution time grows as we add more tests with different severity levels.
Analyze the time complexity of running dbt tests with severity levels.
# Example dbt test configuration with severity
version: 2
models:
- name: customers
tests:
- unique:
severity: error
- not_null:
severity: warn
This snippet shows two tests on a model, each with a severity level that controls how dbt treats failures.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Running each test query on the data model.
- How many times: Once per test defined for the model.
As you add more tests, the total time to run all tests grows roughly in direct proportion.
| Number of Tests (n) | Approx. Operations |
|---|---|
| 10 | 10 test queries run |
| 100 | 100 test queries run |
| 1000 | 1000 test queries run |
Pattern observation: Doubling the number of tests roughly doubles the work done.
Time Complexity: O(n)
This means the time to run tests grows linearly with the number of tests you have.
[X] Wrong: "Severity levels change how many tests run, so time complexity changes."
[OK] Correct: Severity only changes how failures are reported, not how many tests run. All tests still execute, so time grows with test count.
Understanding how test counts affect runtime helps you design efficient data quality checks and explain your choices clearly in discussions.
"What if we grouped tests to run in parallel? How would that affect the time complexity?"
Practice
ERROR do?Solution
Step 1: Understand dbt test severity levels
dbt uses severity levels to decide what happens when a test fails.Step 2: Identify the effect of ERROR severity
When severity is set to ERROR, dbt stops the run immediately on failure.Final Answer:
It stops the dbt run if the test fails. -> Option AQuick Check:
ERROR severity = stops run [OK]
- Confusing ERROR with WARN severity
- Thinking ERROR retries the test
- Assuming ERROR ignores failures
Solution
Step 1: Recall YAML syntax for dbt test severity
dbt expects severity as a key-value pair with uppercase values like WARN or ERROR.Step 2: Identify correct syntax
The correct syntax uses a colon and uppercase WARN:severity: WARN.Final Answer:
severity: WARN -> Option CQuick Check:
YAML key-value with uppercase WARN = correct [OK]
- Using lowercase 'warn' instead of uppercase
- Using equals sign instead of colon
- Spelling severity value incorrectly
tests:
- unique:
column_name: id
severity: WARNWhat happens if the test fails during a dbt run?
Solution
Step 1: Analyze the severity level in the test config
The severity is set to WARN, which means dbt should warn but not stop.Step 2: Understand dbt behavior on WARN severity
When a test fails with WARN severity, dbt logs a warning and continues the run.Final Answer:
The failure is logged as a warning, but the run continues. -> Option AQuick Check:
WARN severity = warn and continue [OK]
- Thinking WARN stops the run
- Assuming WARN ignores failures
- Believing tests retry automatically
tests:
- not_null:
column_name: user_id
severity: ERRORBut your dbt run does not stop when the test fails. What is the likely problem?
Solution
Step 1: Check correct placement of severity in dbt tests
Severity must be set inside theconfigblock, not directly under the test.Step 2: Identify why run does not stop
Since severity is misplaced, dbt ignores it and uses default behavior, so run does not stop.Final Answer:
The severity key is misplaced; it should be under 'config'. -> Option BQuick Check:
Severity must be inside config = The severity key is misplaced; it should be under 'config'. [OK]
- Using lowercase severity value
- Misplacing severity outside config
- Assuming test name is wrong
email column?Solution
Step 1: Recall correct severity placement in dbt YAML
Severity must be inside aconfigblock under each test.Step 2: Match severities to tests as required
Setnot_nullseverity to WARN anduniqueseverity to ERROR inside their config blocks.Final Answer:
Tests with severity inside config: not_null WARN, unique ERROR. -> Option DQuick Check:
Severity inside config with correct WARN/ERROR = tests: - not_null: column_name: email config: severity: WARN - unique: column_name: email config: severity: ERROR [OK]
- Placing severity outside config block
- Swapping WARN and ERROR severities
- Using lowercase severity values
