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
Understanding dbt Project Structure
š Scenario: You are working as a data analyst who wants to organize your data transformation work using dbt (data build tool). You want to create a simple dbt project structure to manage your SQL models and configurations.
šÆ Goal: Build a basic dbt project structure by creating the main folders and files needed to start transforming data with dbt.
š What You'll Learn
Create a models folder with a SQL file inside
Create a dbt_project.yml configuration file
Create a profiles.yml file placeholder for connection settings
Understand the purpose of each file and folder in the dbt project
š” Why This Matters
š Real World
dbt is widely used in data teams to organize and automate data transformations in a clear, maintainable way.
š¼ Career
Understanding dbt project structure is essential for data analysts and engineers working with modern data pipelines and analytics workflows.
Progress0 / 4 steps
1
Create the models folder and a SQL model file
Create a folder named models and inside it create a file named my_first_model.sql with the exact content: select 1 as id.
dbt
Hint
The models folder holds your SQL files that define data transformations. Start with a simple SQL file that selects a constant.
2
Create the dbt_project.yml configuration file
Create a file named dbt_project.yml in the root folder with the exact content: name: 'my_dbt_project'
version: '1.0'
config-version: 2
profile: 'default'
model-paths: ['models']
dbt
Hint
The dbt_project.yml file tells dbt about your project name, version, and where to find your models.
3
Create a placeholder profiles.yml file for connection settings
Create a file named profiles.yml with the exact content: default:
target: dev
outputs:
dev:
type: 'postgres'
host: 'localhost'
user: 'user'
password: 'password'
dbname: 'my_database'
schema: 'public'
dbt
Hint
The profiles.yml file stores your database connection details. This example uses a local Postgres database.
4
Display the dbt project structure summary
Print the exact text: Project structure includes models folder with SQL files, dbt_project.yml config file, and profiles.yml connection file.
dbt
Hint
Use a print statement to show the summary text exactly as given.
Practice
(1/5)
1. Which folder in a dbt project typically contains SQL files that define your data transformations?
easy
A. snapshots/
B. models/
C. macros/
D. tests/
Solution
Step 1: Understand folder purposes
The models/ folder is where SQL files for data transformations live.
Step 2: Identify correct folder for SQL models
Other folders like macros/ hold reusable code, snapshots/ hold snapshot definitions, and tests/ hold test files.
Which file would you edit to add a reusable SQL function?
medium
A. models/customers.sql
B. dbt_project.yml
C. macros/date_utils.sql
D. models/orders.sql
Solution
Step 1: Identify purpose of macros/ folder
The macros/ folder holds reusable SQL functions and macros.
Step 2: Locate reusable function file
The file macros/date_utils.sql is the right place to add reusable SQL functions.
Final Answer:
macros/date_utils.sql -> Option C
Quick Check:
Reusable SQL functions = macros/ folder [OK]
Hint: Reusable SQL code goes in macros/ folder [OK]
Common Mistakes:
Adding functions inside models/ files
Editing dbt_project.yml for SQL code
Confusing macros/ with models/
4. You see this error when running dbt: Compilation Error: Could not find model 'sales_summary'. Which is the most likely cause related to project structure?
medium
A. The 'sales_summary.sql' file is missing from the models/ folder.
B. The 'sales_summary.sql' file is inside the macros/ folder.
C. The dbt_project.yml file is missing.
D. The snapshots/ folder contains 'sales_summary.sql'.
Solution
Step 1: Understand error meaning
The error means dbt cannot find the model named 'sales_summary'.
Step 2: Check model file location
Models must be in the models/ folder. If the file is missing there, dbt can't compile it.
Final Answer:
The 'sales_summary.sql' file is missing from the models/ folder. -> Option A
Quick Check:
Missing model file in models/ causes compilation error [OK]
Hint: Models must be in models/ folder to compile [OK]
Common Mistakes:
Placing model files in macros/ folder
Assuming missing dbt_project.yml causes this error
Confusing snapshots/ with models/
5. You want to organize your dbt project so that models related to customers and orders are in separate folders inside models/. How should you update your dbt_project.yml to reflect this structure?
hard
A. Add models:
my_dbt_project:
+materialized: view only
B. No changes needed; dbt auto-detects subfolders without config
C. Add macros:
my_dbt_project:
customers:
+materialized: table
D. Add models:
my_dbt_project:
customers:
+materialized: table
orders:
+materialized: table
Solution
Step 1: Understand folder-specific config in dbt_project.yml
You can specify configs per subfolder inside models/ by nesting them under your project name.
Step 2: Define separate configs for customers and orders folders
Adding customers: and orders: keys with materialization settings applies configs to those subfolders.