0
0
Apache Airflowdevops~5 mins

Pushing and pulling XCom values in Apache Airflow - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an XCom in Airflow?
An XCom (short for cross-communication) is a way for tasks in Airflow to share small pieces of data or messages between each other during a workflow run.
Click to reveal answer
beginner
How do you push an XCom value in a PythonOperator task?
You can push an XCom by returning a value from the Python function used in the PythonOperator. Airflow automatically pushes the return value as an XCom.
Click to reveal answer
intermediate
How can you pull an XCom value from another task?
Use the task instance's xcom_pull method with the task_id of the task that pushed the value. For example: ti.xcom_pull(task_ids='task_id').
Click to reveal answer
intermediate
What parameters can you use with xcom_pull to get specific data?
You can specify task_ids, key (default is 'return_value'), and include_prior_dates to control which XCom value you want to pull.
Click to reveal answer
advanced
Can you push an XCom manually without returning a value?
Yes, by using the xcom_push method inside a task's context, you can push any key-value pair as an XCom without returning it.
Click to reveal answer
What does Airflow automatically do when a PythonOperator's function returns a value?
ADeletes the return value
BPushes the return value as an XCom
CSaves the return value to a file
DIgnores the return value
Which method is used to retrieve an XCom value from another task?
Axcom_pull
Bxcom_push
Cget_xcom
Dfetch_xcom
What is the default key used when pulling an XCom value if no key is specified?
Areturn_value
Bdefault
Cresult
Dvalue
How can you push an XCom value manually inside a task?
AUsing print statement
BReturning the value from the function
CUsing ti.xcom_push(key, value)
DUsing ti.xcom_pull()
Which of the following is NOT a valid parameter for xcom_pull?
Atask_ids
Bkey
Cinclude_prior_dates
Dpush_value
Explain how to share data between two tasks in Airflow using XComs.
Think about how one task sends and another receives small data pieces.
You got /3 concepts.
    Describe the difference between pushing XComs by returning a value and manually pushing with xcom_push.
    Consider when you want to send multiple or named pieces of data.
    You got /3 concepts.