Model naming conventions in dbt - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the time it takes to run dbt models changes as the number of models grows.
Specifically, how does naming models affect the process of selecting and running them?
Analyze the time complexity of the following dbt model selection snippet.
-- Select models with a specific prefix
models:
+materialized: table
+tags: [finance]
select * from {{ ref('finance_revenue') }}
select * from {{ ref('finance_expenses') }}
select * from {{ ref('marketing_campaigns') }}
This snippet shows selecting models by name prefixes and tags to run specific models.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Searching through the list of model names to find matches by prefix or tag.
- How many times: Once for each model in the project during selection.
As the number of models increases, the time to check each model's name or tag grows linearly.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The number of operations grows directly with the number of models.
Time Complexity: O(n)
This means the time to select models grows in direct proportion to how many models there are.
[X] Wrong: "Naming models with prefixes makes selection instant regardless of project size."
[OK] Correct: Even with prefixes, dbt still checks each model name once, so time grows with the number of models.
Understanding how naming affects model selection time helps you design scalable dbt projects and shows you think about efficiency in real work.
"What if we indexed model names in a dictionary for selection? How would the time complexity change?"
Practice
Solution
Step 1: Understand dbt naming conventions
dbt recommends using clear, lowercase names with underscores to separate words for readability and consistency.Step 2: Evaluate each option
Use clear, lowercase names with underscores to separate words follows the recommended style. Options A, B, and D do not follow best practices.Final Answer:
Use clear, lowercase names with underscores to separate words -> Option AQuick Check:
Clear lowercase with underscores = C [OK]
- Using uppercase letters in model names
- Including spaces or special characters
- Using inconsistent naming styles
Solution
Step 1: Check naming rules for dbt models
Model names should be lowercase and use underscores to separate words, avoiding special characters and uppercase letters.Step 2: Analyze each option
customer_orders uses lowercase letters and underscores only, making it valid. Options B, C, and D contain uppercase letters or special characters.Final Answer:
customer_orders -> Option AQuick Check:
Lowercase with underscores = A [OK]
- Using uppercase letters in model names
- Including hyphens or special characters
- Starting names with numbers
monthly_sales_summarysalesMonthlySummarymonthly-sales-summaryMonthlySalesSummarySolution
Step 1: Identify the best naming style for dbt models
dbt prefers lowercase names with underscores to separate words for clarity and consistency.Step 2: Compare each model name
monthly_sales_summary uses lowercase with underscores and clearly describes the model. Options A and B use camel case or uppercase letters, and C uses hyphens, which are not recommended.Final Answer:
monthly_sales_summary -> Option DQuick Check:
Lowercase with underscores = D [OK]
- Using camelCase or PascalCase
- Using hyphens instead of underscores
- Ignoring clarity in names
CustomerOrders. What is the issue with this name and how can you fix it?Solution
Step 1: Identify naming convention violation
The model name uses uppercase letters, which is against dbt's lowercase naming convention.Step 2: Apply correct naming style
Rename the model to lowercase letters with underscores:customer_orders.Final Answer:
It uses uppercase letters; rename tocustomer_orders-> Option BQuick Check:
Uppercase letters not allowed = A [OK]
- Ignoring uppercase letters in names
- Removing underscores instead of fixing case
- Adding unnecessary special characters
Solution
Step 1: Understand naming best practices
dbt model names should be lowercase, use underscores, and clearly describe the model's content.Step 2: Evaluate each option
total_revenue_per_category_last_year uses lowercase letters and underscores, and clearly describes the model. Options A and C use uppercase or camel case, and D uses hyphens.Final Answer:
total_revenue_per_category_last_year -> Option CQuick Check:
Lowercase with underscores and clear description = B [OK]
- Using camelCase or PascalCase
- Using hyphens instead of underscores
- Using uppercase letters
