Challenge - 5 Problems
Source Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of source() function call in dbt
Given the following dbt model code snippet, what will be the output SQL generated for the source table reference?
dbt
select * from {{ source('raw_data', 'users') }}
Attempts:
2 left
💡 Hint
The source() function returns a fully qualified table name using the source schema and table name.
✗ Incorrect
The source() function in dbt returns the fully qualified table name in the format schema.table, so {{ source('raw_data', 'users') }} becomes raw_data.users in SQL.
🧠 Conceptual
intermediate1:30remaining
Purpose of source() function in dbt
What is the main purpose of using the source() function in a dbt model?
Attempts:
2 left
💡 Hint
Think about how dbt tracks raw data sources and their metadata.
✗ Incorrect
The source() function is used to reference raw tables defined in source.yml files. This helps dbt track data lineage and generate documentation for raw data sources.
🔧 Debug
advanced2:00remaining
Identify the error in source() usage
What error will occur when running this dbt model code?
select * from {{ source('raw_data') }}
dbt
select * from {{ source('raw_data') }}
Attempts:
2 left
💡 Hint
Check the number of arguments source() expects.
✗ Incorrect
The source() function requires exactly two arguments: the source name and the table name. Omitting the table name causes a compilation error.
❓ data_output
advanced2:00remaining
Resulting SQL from nested source() usage
What is the resulting SQL query from this dbt model code?
select user_id, count(*) from {{ source('raw_data', 'events') }} group by user_id
dbt
select user_id, count(*) from {{ source('raw_data', 'events') }} group by user_id
Attempts:
2 left
💡 Hint
Remember how source() resolves to schema.table format.
✗ Incorrect
The source() function returns the fully qualified table name in the format schema.table, so the SQL becomes select user_id, count(*) from raw_data.events group by user_id.
🚀 Application
expert2:30remaining
Using source() with multiple environments
In a dbt project with multiple environments (dev, prod), how does the source() function help manage raw table references across environments?
Attempts:
2 left
💡 Hint
Think about how dbt profiles and source configurations work.
✗ Incorrect
The source() function uses the schema defined in the source configuration, which can be set differently per environment in the dbt profiles. This allows the same model code to reference the correct raw tables in dev or prod without changes.