Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @dag instead of @task for the function.
Using @operator which is not a valid decorator here.
✗ Incorrect
The @task decorator defines a task in the TaskFlow API.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function object
extract instead of calling it.Calling the wrong function.
✗ Incorrect
Calling extract() runs the task and passes its output to process.
3fill in blank
hardFix 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'
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.
✗ Incorrect
Tasks must return values to push them to XCom for downstream tasks.
4fill in blank
hardFill 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'
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.
✗ Incorrect
Assign the output of process to result and pass data as input.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong variable to transform.
Calling load with raw instead of transformed data.
✗ Incorrect
Call extract() to get raw data, pass it to transform, then load the transformed data.