0
0
dbtdata~20 mins

Organizing models in directories in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Directory Mastery in dbt
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding model directory structure in dbt

In dbt, how does organizing models into subdirectories affect the resulting database schema and table names?

AModels in subdirectories are flattened into the same schema as the root models folder, ignoring folder names.
BEach subdirectory creates a separate database, isolating models completely.
CSubdirectories in the models folder create nested schemas in the database, reflecting the folder structure.
DModels in subdirectories are ignored unless explicitly referenced in the dbt_project.yml file.
Attempts:
2 left
💡 Hint

Think about how dbt treats folder names by default when building models.

Predict Output
intermediate
2:00remaining
Output schema and table name from nested model

Given the following dbt model file path and configuration, what will be the schema and table name of the compiled model?

models/sales/2024/orders.sql

dbt_project.yml contains:

models:
  sales:
    +schema: sales_data
dbt
select * from raw.orders
ASchema: public, Table: orders
BSchema: sales, Table: orders
CSchema: sales_data, Table: orders
DSchema: sales_data, Table: sales_2024_orders
Attempts:
2 left
💡 Hint

Check how the +schema config applies to subdirectories.

data_output
advanced
2:00remaining
Resulting model names from multiple directories

Consider a dbt project with these model files:

  • models/customers.sql
  • models/finance/invoices.sql
  • models/finance/2024/payments.sql

With no special schema or alias configurations, what are the compiled table names for these models?

Acustomers, finance_invoices, finance_2024_payments
Bcustomers, invoices, payments
Ccustomers, invoices, finance_2024_payments
Dcustomers, finance_invoices, payments
Attempts:
2 left
💡 Hint

Think about how dbt names tables by default from file names.

🔧 Debug
advanced
2:00remaining
Why is a model not found after moving to a subdirectory?

A model 'sales_summary.sql' was moved from models/ to models/sales/. After running dbt, a downstream model referencing it fails with 'model not found'. What is the most likely cause?

AThe model was not added to the manifest because subdirectories are ignored by dbt.
Bdbt requires updating the dbt_project.yml to include new subdirectories explicitly.
CThe model file name must be changed to include the subdirectory name.
DThe downstream model's ref() call did not update to include the subdirectory path.
Attempts:
2 left
💡 Hint

Check how dbt's ref() function resolves model names.

🚀 Application
expert
3:00remaining
Configuring dbt to create schemas matching model directories

You want dbt to create separate schemas in the database that match your model directory names (e.g., models/sales/ creates schema 'sales'). Which configuration achieves this behavior?

AUse the <code>+schema</code> config with a Jinja expression referencing <code>this.path</code> and the model path.
BSet <code>generate_schema_name</code> in dbt_project.yml to use the directory name dynamically.
CSet <code>materialized: ephemeral</code> on all models in subdirectories.
DRename all model files to include the directory name as a prefix.
Attempts:
2 left
💡 Hint

Look into how to use Jinja in model configs to customize schema names.