0
0
Apache Airflowdevops~20 mins

XCom with return values in Apache Airflow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
XCom Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
XCom Push and Pull Output
Given the following Airflow task code, what will be the output of the XCom pull in the downstream task?
Apache Airflow
def push_function(ti):
    ti.xcom_push(key='result', value=42)

def pull_function(ti):
    value = ti.xcom_pull(key='result', task_ids='push_task')
    print(value)

# Assume push_function runs as 'push_task' and pull_function runs as 'pull_task' downstream.
A0
BNone
CKeyError
D42
Attempts:
2 left
💡 Hint
Remember that xcom_push stores a value with a key, and xcom_pull retrieves it using the same key and task id.
🧠 Conceptual
intermediate
1:30remaining
XCom Return Value Behavior
What happens when a PythonOperator task returns a value in Airflow?
AThe return value is ignored and not stored anywhere.
BThe return value is automatically pushed to XCom with key 'return_value'.
CThe return value causes the task to fail.
DThe return value is stored in a log file only.
Attempts:
2 left
💡 Hint
Think about how Airflow captures outputs from PythonOperator tasks.
Troubleshoot
advanced
2:30remaining
XCom Pull Returns None
You have two tasks: 'task_a' pushes a value to XCom with key 'data'. 'task_b' tries to pull this value but gets None. What is the most likely cause?
A'task_a' did not push any value to XCom.
BThe key used in xcom_pull is misspelled.
CAll of the above.
D'task_b' is running before 'task_a' completes.
Attempts:
2 left
💡 Hint
Consider timing, key names, and whether the push actually happened.
🔀 Workflow
advanced
2:00remaining
XCom Usage in Task Dependencies
Which Airflow DAG setup correctly ensures that a value pushed by 'task1' is available to 'task2' via XCom?
A'task1' >> 'task2' with 'task2' pulling XCom using task_ids='task1'.
B'task2' >> 'task1' with 'task2' pulling XCom using task_ids='task1'.
C'task1' and 'task2' run in parallel with no dependencies.
D'task1' pushes XCom but 'task2' does not pull it.
Attempts:
2 left
💡 Hint
Think about task order and how XCom pull uses task_ids.
Best Practice
expert
3:00remaining
Best Practice for Large Data in XCom
What is the best practice when you need to share large data between Airflow tasks using XCom?
AStore the large data in external storage (e.g., S3) and push only a reference or path via XCom.
BPush the entire large data directly via XCom for simplicity.
CSplit the large data into many small pieces and push each piece separately via XCom.
DAvoid using XCom and rewrite tasks to not share data.
Attempts:
2 left
💡 Hint
Consider XCom size limits and performance.