0
0
dbtdata~5 mins

Custom singular tests in dbt - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Custom singular tests
O(n)
Understanding Time Complexity

When we write custom singular tests in dbt, we want to know how the time to run these tests changes as our data grows.

We ask: How does the test execution time grow when the data size increases?

Scenario Under Consideration

Analyze the time complexity of the following dbt custom singular test.


select
  count(*) as error_count
from {{ model }}
where some_column is null
    

This test counts how many rows in a model have a null value in a specific column.

Identify Repeating Operations

Look for repeated actions in the test query.

  • Primary operation: Scanning all rows in the model to check the column value.
  • How many times: Once for each row in the model.
How Execution Grows With Input

The test checks every row once, so if the number of rows grows, the work grows too.

Input Size (n)Approx. Operations
1010 checks
100100 checks
10001000 checks

Pattern observation: The number of operations grows directly with the number of rows.

Final Time Complexity

Time Complexity: O(n)

This means the test takes longer in direct proportion to the number of rows it checks.

Common Mistake

[X] Wrong: "The test runs instantly no matter how big the data is."

[OK] Correct: Because the test looks at every row, more rows mean more work and more time.

Interview Connect

Understanding how tests scale with data size helps you write efficient checks and shows you think about performance in real projects.

Self-Check

"What if the test checked two columns instead of one? How would the time complexity change?"