0
0
Apache Airflowdevops~10 mins

Why branching handles conditional logic in Apache Airflow - Test Your Understanding

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

Complete the code to create a BranchPythonOperator that decides the next task based on a condition.

Apache Airflow
branch_task = BranchPythonOperator(task_id='branching', python_callable=[1], dag=dag)
Drag options to blanks, or click blank then click option'
Abranch_logic
Brun_task
Cchoose_branch
Dstart_branch
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a function name
Passing a task instead of a callable
2fill in blank
medium

Complete the function to return the correct task_id based on the value of condition.

Apache Airflow
def choose_branch():
    condition = True
    if condition:
        return [1]
    else:
        return 'task_b'
Drag options to blanks, or click blank then click option'
A'task_a'
B'task_c'
C'branch_task'
D'start_task'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a variable instead of a string
Missing quotes around the task_id
3fill in blank
hard

Fix the error in the BranchPythonOperator definition by completing the missing parameter.

Apache Airflow
branch_task = BranchPythonOperator(task_id='branching', python_callable=choose_branch, [1]=dag)
Drag options to blanks, or click blank then click option'
Astart_date
Bschedule_interval
Cdefault_args
Ddag
Attempts:
3 left
💡 Hint
Common Mistakes
Using schedule_interval instead of dag
Omitting the DAG parameter
4fill in blank
hard

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

Apache Airflow
with DAG('branching_dag', start_date=days_ago(1), schedule_interval='@daily') as dag:
    branch = BranchPythonOperator(task_id='branch', python_callable=[1])
    task_a = DummyOperator(task_id=[2])
    task_b = DummyOperator(task_id='task_b')
    branch >> [task_a, task_b]
Drag options to blanks, or click blank then click option'
Achoose_branch
B'task_a'
C'branch_task'
Drun_branch
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching task_id and return value
Wrong function name in callable
5fill in blank
hard

Fill all three blanks to define a branching function that returns different task_ids based on a variable.

Apache Airflow
def choose_branch():
    value = 10
    if value > [1]:
        return [2]
    else:
        return [3]
Drag options to blanks, or click blank then click option'
A5
B'task_high'
C'task_low'
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers instead of strings for task_ids
Wrong comparison operator