0
0
Apache Airflowdevops~10 mins

XCom size limitations and alternatives 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 push a small value to XCom in an Airflow task.

Apache Airflow
task_instance.xcom_push(key='my_key', value=[1])
Drag options to blanks, or click blank then click option'
Arange(1000)
Bopen('file.txt')
Clambda x: x+1
D'small_data'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to push large objects like files or functions to XCom.
2fill in blank
medium

Complete the code to pull a value from XCom in an Airflow task.

Apache Airflow
value = task_instance.xcom_pull(task_ids=[1], key='my_key')
Drag options to blanks, or click blank then click option'
ANone
B'non_existing_task'
C'previous_task'
D123
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong or non-existing task IDs when pulling XCom values.
3fill in blank
hard

Fix the error in the code that tries to push a large file content to XCom.

Apache Airflow
with open('large_file.txt', 'r') as f:
    content = f.read()
task_instance.xcom_push(key='file_content', value=[1])
Drag options to blanks, or click blank then click option'
Alen(content)
Bcontent
Cf
D'content'
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing entire large file content causing XCom size errors.
4fill in blank
hard

Fill both blanks to store a large result outside XCom and push its path instead.

Apache Airflow
result_path = '/tmp/result.json'
with open(result_path, 'w') as f:
    json.dump([1], f)
task_instance.xcom_push(key='result_path', value=[2])
Drag options to blanks, or click blank then click option'
Alarge_result
Bresult_path
C'large_result'
D'result_path'
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing large data directly to XCom instead of a file path.
5fill in blank
hard

Fill all three blanks to read a large result from a file path pulled from XCom.

Apache Airflow
result_path = task_instance.xcom_pull(task_ids=[1], key=[2])
with open(result_path, [3]) as f:
    result = json.load(f)
Drag options to blanks, or click blank then click option'
A'previous_task'
B'result_path'
C'r'
D'my_key'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys or task IDs when pulling XCom data.
Opening the file in wrong mode.