0
0
Apache Airflowdevops~10 mins

BranchPythonOperator in Apache Airflow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the BranchPythonOperator from Airflow.

Apache Airflow
from airflow.operators.[1] import BranchPythonOperator
Drag options to blanks, or click blank then click option'
Abash
Bbranch
Cdummy
Dpython
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bash' instead of 'python' for the import.
Trying to import from a non-existing 'branch' module.
2fill in blank
medium

Complete the code to define the branch function that decides the next task.

Apache Airflow
def choose_branch():
    if condition:
        return [1]
    else:
        return 'task_b'
Drag options to blanks, or click blank then click option'
A'task_a'
Btask_a
Ctask_b
D'choose_branch'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the variable name without quotes.
Returning the function name instead of a task id.
3fill in blank
hard

Fix the error in the BranchPythonOperator instantiation by completing the missing argument.

Apache Airflow
branch_task = BranchPythonOperator(
    task_id='branching',
    python_callable=[1],
    dag=dag
)
Drag options to blanks, or click blank then click option'
A'choose_branch'
Bchoose_branch()
Cchoose_branch
Dbranching
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function with parentheses instead of passing it.
Passing the function name as a string.
4fill in blank
hard

Fill both blanks to set dependencies so branch_task runs before task_a and task_b.

Apache Airflow
branch_task [1] task_a
branch_task [2] task_b
Drag options to blanks, or click blank then click option'
A>>
B<<
C->
D<-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<<' which sets upstream dependencies incorrectly.
Using arrows like '->' or '<-' which are not valid in Airflow.
5fill in blank
hard

Fill all three blanks to create a DAG with BranchPythonOperator and two downstream tasks.

Apache Airflow
with DAG('branch_dag', start_date=days_ago(1)) as dag:
    branch_task = BranchPythonOperator(
        task_id=[1],
        python_callable=[2]
    )
    task_a = DummyOperator(task_id='task_a')
    task_b = DummyOperator(task_id='task_b')
    branch_task [3] task_a
    branch_task >> task_b
Drag options to blanks, or click blank then click option'
A'branching'
Bchoose_branch
C>>
Dtask_a
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the task_id string.
Calling the function instead of passing it.
Using wrong operators for dependencies.