0
0
dbtdata~20 mins

Orchestrating dbt with Airflow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
dbt Airflow Orchestrator
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Airflow DAG snippet?
Given this Airflow DAG code snippet that runs a dbt command, what will be the output in the Airflow logs when the task runs successfully?
dbt
from airflow import DAG
from airflow.operators.bash import BashOperator
from datetime import datetime

with DAG('dbt_run_dag', start_date=datetime(2024, 1, 1), schedule_interval='@daily') as dag:
    run_dbt = BashOperator(
        task_id='run_dbt_models',
        bash_command='dbt run --profiles-dir /usr/local/dbt_profiles'
    )
ALogs show dbt command not found error
BLogs show a Python syntax error due to missing import
CLogs show Airflow task failure due to missing DAG start_date
DLogs show dbt running models and completing with 'Completed successfully' message
Attempts:
2 left
💡 Hint
Check if the DAG has a valid start_date and the bash command is correct.
data_output
intermediate
1:30remaining
What is the value of the Airflow task instance state after dbt run succeeds?
If an Airflow task runs a dbt command using BashOperator and the dbt run finishes without errors, what will be the task instance state in Airflow's metadata database?
Afailed
Bsuccess
Cup_for_retry
Dskipped
Attempts:
2 left
💡 Hint
Think about what Airflow marks a task when the command it runs exits with code 0.
🔧 Debug
advanced
2:30remaining
Why does this Airflow DAG fail to run dbt models?
This Airflow DAG fails with an error: 'bash: dbt: command not found'. What is the most likely cause?
dbt
from airflow import DAG
from airflow.operators.bash import BashOperator
from datetime import datetime

with DAG('dbt_fail_dag', start_date=datetime(2024, 1, 1), schedule_interval='@daily') as dag:
    run_dbt = BashOperator(
        task_id='run_dbt',
        bash_command='dbt run'
    )
Adbt is not installed or not in the PATH of the Airflow worker environment
BThe DAG is missing a schedule_interval
CThe start_date is in the past
DThe task_id is invalid
Attempts:
2 left
💡 Hint
Check the environment where Airflow runs the bash command.
🧠 Conceptual
advanced
3:00remaining
What is the best way to pass dynamic variables to dbt models in Airflow?
You want to run dbt models in Airflow and pass a variable that changes daily, such as a date. Which approach is best to pass this variable to dbt?
AUse the --vars flag with a JSON string in the bash_command, e.g., dbt run --vars '{"date": "2024-01-01"}'
BSet environment variables in Airflow and access them directly in dbt without passing --vars
CModify the dbt profiles.yml file daily to include the variable
DHardcode the variable inside the dbt model SQL files
Attempts:
2 left
💡 Hint
Think about how dbt accepts variables at runtime.
🚀 Application
expert
4:00remaining
How to orchestrate dbt model runs with dependencies in Airflow?
You have two dbt models: model_a and model_b. model_b depends on model_a. You want to run them in Airflow ensuring model_b runs only after model_a completes successfully. How do you set this up?
AUse Airflow's PythonOperator to run dbt models in parallel without dependencies
BRun both models in a single dbt run command in one BashOperator task
CCreate two BashOperator tasks in Airflow, one for each model, and set run_model_b.set_upstream(run_model_a)
DCreate one BashOperator task that runs model_b only, since dbt handles dependencies internally
Attempts:
2 left
💡 Hint
Consider how Airflow manages task dependencies explicitly.