Bird
Raised Fist0
Apache Airflowdevops~20 mins

Execution date vs logical date in Apache Airflow - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Execution Date Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Airflow Execution Date

In Apache Airflow, what does the execution date represent?

AThe date and time when the DAG was last modified.
BThe date and time when the task actually runs on the system.
CThe current system date and time when the DAG is triggered manually.
DThe logical date and time for which the DAG run is scheduled, representing the data interval start.
Attempts:
2 left
💡 Hint

Think about what Airflow uses to identify the data period a DAG run is processing.

💻 Command Output
intermediate
1:30remaining
Output of Airflow DAG Run Dates

Given a DAG scheduled to run daily starting at 2024-06-01, if a DAG run starts at 2024-06-02 01:00 AM, what is the execution date shown in the Airflow UI for this run?

A2024-06-01 00:00:00
B2024-06-02 01:00:00
C2024-06-02 00:00:00
D2024-06-03 00:00:00
Attempts:
2 left
💡 Hint

Remember that execution date points to the start of the data interval, not the actual run time.

🔀 Workflow
advanced
2:00remaining
Airflow Logical Date vs Execution Date in Backfill

You run an Airflow backfill command for a DAG with daily schedule from 2024-05-28 to 2024-05-30. Which dates will be used as execution dates for the backfill runs?

A2024-05-29, 2024-05-30, 2024-05-31
B2024-05-28, 2024-05-29, 2024-05-30
C2024-05-27, 2024-05-28, 2024-05-29
D2024-05-30, 2024-05-31, 2024-06-01
Attempts:
2 left
💡 Hint

Execution dates correspond to the logical schedule dates you specify for backfill.

❓ Troubleshoot
advanced
2:00remaining
Troubleshooting Unexpected Execution Date in Airflow

You notice that a DAG run triggered manually shows an execution date of 2024-06-01 00:00:00, even though you triggered it on 2024-06-05. Why does this happen?

AManual triggers always use the current system date as execution date.
BThe DAG schedule interval is ignored for manual triggers, so execution date is random.
CManual triggers use the logical execution date you specify or default to the previous scheduled interval start.
DAirflow has a bug causing execution dates to not update on manual triggers.
Attempts:
2 left
💡 Hint

Think about how Airflow assigns execution dates for manual runs.

✅ Best Practice
expert
2:30remaining
Best Practice for Using Execution Date in Airflow Tasks

Which is the best practice for using the execution date inside an Airflow task to process data?

AUse the execution date as the start of the data interval and calculate the end date by adding the schedule interval.
BUse the current system date and time to process data, ignoring the execution date.
CUse the execution date as the exact timestamp to fetch data only for that second.
DUse a fixed date hardcoded in the DAG to avoid confusion.
Attempts:
2 left
💡 Hint

Think about how to define the data interval for processing in scheduled DAGs.

Practice

(1/5)
1. What does the logical date in Airflow represent?
easy
A. The time period the task is processing data for
B. The exact time the task started running
C. The current system time when the task runs
D. The time when the DAG was created

Solution

  1. Step 1: Understand the definition of logical date

    The logical date is the timestamp representing the data interval the task is working on, not when it runs.
  2. Step 2: Differentiate from execution date

    Execution date is when the task actually runs, but logical date points to the data period it processes.
  3. Final Answer:

    The time period the task is processing data for -> Option A
  4. Quick Check:

    Logical date = data period [OK]
Hint: Logical date = data period, execution date = run time [OK]
Common Mistakes:
  • Confusing logical date with actual run time
  • Thinking logical date is current system time
  • Mixing execution date with DAG creation time
2. Which of the following is the correct way to access the logical date inside an Airflow task?
easy
A. Using context['execution_date']
B. Using context['logical_date']
C. Using context['run_time']
D. Using context['start_date']

Solution

  1. Step 1: Recall Airflow context variables

    Airflow provides logical_date in the context to represent the logical date of the task instance.
  2. Step 2: Identify the correct key for logical date

    The key 'logical_date' is used to access the logical date, while 'execution_date' is deprecated in newer versions.
  3. Final Answer:

    Using context['logical_date'] -> Option B
  4. Quick Check:

    Access logical date with context['logical_date'] [OK]
Hint: Use context['logical_date'] for logical date in Airflow 2.2+ [OK]
Common Mistakes:
  • Using deprecated 'execution_date' key
  • Trying to access logical date with 'run_time'
  • Confusing start_date with logical date
3. Given a DAG scheduled daily at midnight, if a task runs on 2024-06-10 00:00 UTC, what is its logical date?
medium
A. 2024-06-10 00:00 UTC
B. 2024-06-11 00:00 UTC
C. 2024-06-09 00:00 UTC
D. The current system time when the task runs

Solution

  1. Step 1: Understand daily scheduling in Airflow

    A DAG scheduled daily at midnight runs for the data of the previous day, so the logical date is the start of that previous day.
  2. Step 2: Calculate logical date for run on 2024-06-10 00:00 UTC

    The run at midnight on June 10 processes data for June 9, so logical date is 2024-06-09 00:00 UTC.
  3. Final Answer:

    2024-06-09 00:00 UTC -> Option C
  4. Quick Check:

    Run time = June 10, logical date = June 9 [OK]
Hint: Logical date is previous day for daily midnight runs [OK]
Common Mistakes:
  • Assuming logical date equals execution date
  • Using current system time as logical date
  • Confusing next day as logical date
4. You see a task's logs showing execution_date as 2024-06-10 but the data processed is from 2024-06-11. What is the likely issue?
medium
A. The task is running twice for the same data
B. The DAG schedule interval is set to hourly instead of daily
C. The system clock is incorrect
D. The task is using execution_date instead of logical_date for data filtering

Solution

  1. Step 1: Analyze mismatch between execution_date and data date

    If data processed is from a later date than execution_date, the task likely uses execution_date (run time) instead of logical_date (data period) for filtering.
  2. Step 2: Understand correct usage of logical date

    Logical date should be used to select data for the intended period; using execution_date causes off-by-one errors.
  3. Final Answer:

    The task is using execution_date instead of logical_date for data filtering -> Option D
  4. Quick Check:

    Use logical_date for data period, not execution_date [OK]
Hint: Use logical_date for data filtering, not execution_date [OK]
Common Mistakes:
  • Ignoring difference between execution and logical dates
  • Assuming schedule interval causes date mismatch
  • Blaming system clock without checking code
5. You want to process hourly data with a DAG scheduled every hour. The task should process data for the previous hour. Which date should you use inside the task to filter data correctly?
hard
A. Use logical_date which represents the data interval start
B. Use DAG start_date
C. Use current system time when the task runs
D. Use execution_date which is the task run time

Solution

  1. Step 1: Understand hourly scheduling and data processing

    For hourly DAGs, the logical date marks the start of the hour for which data is processed, typically the previous hour.
  2. Step 2: Choose the correct date for filtering data

    Using logical_date ensures the task filters data for the correct hour interval, not the actual run time.
  3. Final Answer:

    Use logical_date which represents the data interval start -> Option A
  4. Quick Check:

    Hourly data uses logical_date for correct filtering [OK]
Hint: For hourly data, always use logical_date for filtering [OK]
Common Mistakes:
  • Using execution_date causes off-by-one hour errors
  • Using current time ignores schedule intervals
  • Confusing DAG start_date with data interval
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard