0
0
Apache Airflowdevops~20 mins

Creating a basic DAG file in Apache Airflow - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Airflow DAG Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a simple Airflow DAG run
Given this Airflow DAG code, what will be the output when the task runs successfully?
Apache Airflow
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime

def greet():
    print('Hello from Airflow!')

default_args = {
    'start_date': datetime(2024, 1, 1)
}

dag = DAG('greet_dag', default_args=default_args, schedule_interval='@daily')

task = PythonOperator(
    task_id='greet_task',
    python_callable=greet,
    dag=dag
)
AHello from Airflow!
BTask greet_task failed
CSyntaxError: invalid syntax
DNo output because DAG is paused
Attempts:
2 left
💡 Hint
The PythonOperator runs the greet function which prints a message.
🧠 Conceptual
intermediate
1:30remaining
Understanding DAG schedule_interval
What does the schedule_interval='@hourly' mean in an Airflow DAG?
AThe DAG runs once every minute
BThe DAG runs once every day
CThe DAG runs once every hour
DThe DAG runs only once at start_date
Attempts:
2 left
💡 Hint
Think about how often '@hourly' triggers the DAG.
Configuration
advanced
2:00remaining
Correct DAG default_args configuration
Which option correctly sets the default_args for an Airflow DAG with a start date of January 1, 2024, and retries set to 3?
A{'start_date': datetime(2024, 1, 1), 'retries': 3}
B{'start_date': '2024-01-01', 'retries': '3'}
C{start_date: datetime(2024, 1, 1), retries: 3}
D{'start_date': datetime(2024, 1, 1), retries: 'three'}
Attempts:
2 left
💡 Hint
Check the types of values and syntax for dictionary keys and values.
Troubleshoot
advanced
2:00remaining
Identifying error in DAG task definition
What error will occur with this task definition in an Airflow DAG? from airflow.operators.python import PythonOperator task = PythonOperator( task_id='task1' python_callable=lambda: print('Hi') dag=dag )
ANameError: name 'dag' is not defined
BSyntaxError: missing comma between arguments
CTypeError: python_callable must be a function
DNo error, task will run successfully
Attempts:
2 left
💡 Hint
Look carefully at the commas separating arguments in the function call.
🔀 Workflow
expert
3:00remaining
Order of steps to create and run a basic Airflow DAG
What is the correct order of steps to create and run a basic Airflow DAG?
A1,3,2,4
B3,2,1,4
C2,1,3,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Think about writing code first, then placing it, then starting services, then running.