Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the DAG class from Airflow.
Apache Airflow
from airflow.[1] import DAG
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing DAG from operators or hooks instead of models.
✗ Incorrect
The DAG class is imported from the models module in Airflow.
2fill in blank
mediumComplete the code to set the schedule interval for a DAG to run daily.
Apache Airflow
dag = DAG('example_dag', schedule_interval=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@hourly' or '@weekly' instead of '@daily'.
✗ Incorrect
The schedule_interval set to '@daily' makes the DAG run once every day.
3fill in blank
hardFix the error in the task definition by completing the operator import.
Apache Airflow
from airflow.operators.[1] import BashOperator
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing BashOperator from python or dummy modules.
✗ Incorrect
The BashOperator is imported from the bash module inside operators.
4fill in blank
hardFill both blanks to create a task that runs a bash command in the DAG.
Apache Airflow
task1 = [1](task_id='print_date', bash_command=[2], dag=dag)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using PythonOperator instead of BashOperator.
Using wrong bash command string.
✗ Incorrect
The task uses BashOperator and runs the 'date' command.
5fill in blank
hardFill all three blanks to define a DAG with default args and a Python task.
Apache Airflow
from datetime import datetime default_args = {'owner': [1], 'start_date': [2] dag = DAG('my_dag', default_args=default_args, schedule_interval='@daily') def my_task(): print('Hello Airflow') task = [3](task_id='print_hello', python_callable=my_task, dag=dag)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using BashOperator for a Python task.
Wrong format for start_date.
Owner not a string.
✗ Incorrect
The owner is a string, the start_date is a datetime object, and the task uses PythonOperator to run Python code.