0
0
Apache Airflowdevops~10 mins

TaskFlow API for cleaner XCom 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 define a task using the TaskFlow API decorator.

Apache Airflow
@dag
 def my_dag():
     @[1]
     def extract():
         return 'data'
Drag options to blanks, or click blank then click option'
Apython
Boperator
Ctask
Ddag
Attempts:
3 left
💡 Hint
Common Mistakes
Using @dag instead of @task for the function.
Using @operator which is not a valid decorator here.
2fill in blank
medium

Complete the code to pass data between tasks using the TaskFlow API.

Apache Airflow
@dag
 def my_dag():
     @task
     def extract():
         return 'data'

     @task
     def process(data):
         print(data)

     processed = process([1])
Drag options to blanks, or click blank then click option'
Aextract()
Bextract
Cprocess()
Dprocess
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function object extract instead of calling it.
Calling the wrong function.
3fill in blank
hard

Fix the error in the task definition to correctly return a value for XCom.

Apache Airflow
@dag
 def my_dag():
     @task
     def extract():
         [1] 'data'
Drag options to blanks, or click blank then click option'
Areturn
Bprint
Cyield
Dpass
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of return, which does not push data to XCom.
Using yield which is for generators, not needed here.
4fill in blank
hard

Fill both blanks to create a DAG that runs the tasks in order using the TaskFlow API.

Apache Airflow
@dag
 def my_dag():
     @task
     def extract():
         return 'data'

     @task
     def process(data):
         print(data)

     data = extract()
     [1] = process([2])
Drag options to blanks, or click blank then click option'
Aresult
Bdata
Cextract()
Dprocess()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function call extract() again instead of the variable.
Not assigning the output of process to a variable.
5fill in blank
hard

Fill all three blanks to define a DAG with three tasks where data flows from extract to transform to load.

Apache Airflow
@dag
 def my_dag():
     @task
     def extract():
         return 'raw data'

     @task
     def transform(data):
         return data.upper()

     @task
     def load(data):
         print(f'Loading: {data}')

     raw = [1]()
     transformed = [2]([3])
     load(transformed)
Drag options to blanks, or click blank then click option'
Aextract
Btransform
Craw
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong variable to transform.
Calling load with raw instead of transformed data.