0
0
dbtdata~5 mins

Naming conventions at scale in dbt - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Naming conventions at scale
O(n)
Understanding Time Complexity

When working with many dbt models, naming conventions help organize and find things quickly.

We want to understand how the effort to manage names grows as the number of models increases.

Scenario Under Consideration

Analyze the time complexity of the following dbt naming convention check.


    {% for model in graph.nodes.values() %}
      {% if not model.name.startswith('stg_') and model.resource_type == 'model' %}
        {{ exceptions.raise_compiler_error('Model name must start with stg_') }}
      {% endif %}
    {% endfor %}
    

This code loops over all models and checks if their names follow the 'stg_' prefix rule.

Identify Repeating Operations

Look for repeated actions in the code.

  • Primary operation: Looping over all models in the project.
  • How many times: Once for each model, so as many times as there are models.
How Execution Grows With Input

As the number of models grows, the checks grow too.

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

Pattern observation: The number of checks grows directly with the number of models.

Final Time Complexity

Time Complexity: O(n)

This means the time to check naming grows in a straight line as you add more models.

Common Mistake

[X] Wrong: "Checking names only once is enough, no matter how many models there are."

[OK] Correct: Each model needs its own check, so the total work grows with the number of models.

Interview Connect

Understanding how checks scale helps you design dbt projects that stay manageable as they grow.

Self-Check

"What if we grouped models by folder and checked naming only once per folder? How would the time complexity change?"