Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Organizing models in directories
📖 Scenario: You are working on a data project using dbt. Your project has many data models. To keep things neat and easy to find, you want to organize these models into folders (directories).Think of it like organizing your school notes into different notebooks by subject. This helps you find what you need quickly.
🎯 Goal: You will create a folder structure inside the models directory and place model files in the right folders. Then, you will write a simple model SQL file inside a folder.
📋 What You'll Learn
Create a folder named sales inside the models directory
Create a folder named marketing inside the models directory
Create a model file named daily_sales.sql inside the sales folder
Write a simple SQL SELECT statement inside daily_sales.sql that selects all columns from raw_sales table
💡 Why This Matters
🌍 Real World
Organizing models in folders helps teams manage many data models clearly and avoid confusion.
💼 Career
Data analysts and engineers often organize dbt projects this way to improve collaboration and maintainability.
Progress0 / 4 steps
1
Create folders inside the models directory
Create two folders named sales and marketing inside the models directory of your dbt project.
dbt
Hint
Use your file explorer or terminal commands like mkdir models/sales and mkdir models/marketing.
2
Create a model file inside the sales folder
Inside the models/sales folder, create a file named daily_sales.sql.
dbt
Hint
Create the file using your text editor or terminal command like touch models/sales/daily_sales.sql.
3
Write a simple SQL SELECT statement in daily_sales.sql
Open the models/sales/daily_sales.sql file and write this exact SQL code: SELECT * FROM raw_sales;
dbt
Hint
This SQL selects all columns from the raw_sales table.
4
Display the path and content of the daily_sales.sql model
Print the path models/sales/daily_sales.sql and then print the content of the file exactly as: SELECT * FROM raw_sales;
dbt
Hint
Use two print statements: one for the path, one for the SQL content.
Practice
(1/5)
1. Why is it helpful to organize dbt models into directories?
easy
A. It keeps the project clean and easier to manage.
B. It makes dbt run faster.
C. It prevents errors in SQL syntax.
D. It automatically creates dashboards.
Solution
Step 1: Understand project organization benefits
Organizing files into folders helps keep things tidy and easy to find.
Step 2: Relate to dbt model management
In dbt, directories group models logically, making the project easier to manage.
Final Answer:
It keeps the project clean and easier to manage. -> Option A
Quick Check:
Organizing models = easier management [OK]
Hint: Folders group models logically for clarity [OK]
Common Mistakes:
Thinking folders speed up dbt runs
Believing folders fix SQL errors
Assuming folders create dashboards automatically
2. Which of the following is the correct way to reference a model in a subdirectory in dbt SQL?
easy
A. SELECT * FROM subfolder-model_name
B. SELECT * FROM model_name.subfolder
C. SELECT * FROM subfolder.model_name
D. SELECT * FROM model_name
Solution
Step 1: Understand dbt model referencing
dbt uses dot notation to reference models in subfolders: folder.model_name.
Step 2: Check each option
Only SELECT * FROM subfolder.model_name uses correct dot notation with folder before model name.
Final Answer:
SELECT * FROM subfolder.model_name -> Option C
Quick Check:
Use folder.model_name to reference subfolder models [OK]