|
16 | 16 | under the License. |
17 | 17 |
|
18 | 18 | .. _dynamic-task-mapping: |
| 19 | +.. _mapped-tasks: |
19 | 20 |
|
20 | | -==================== |
21 | | -Dynamic Task Mapping |
22 | | -==================== |
| 21 | +============ |
| 22 | +Mapped tasks |
| 23 | +============ |
23 | 24 |
|
24 | | -Dynamic Task Mapping allows a way for a workflow to create a number of tasks at runtime based upon current data, rather than the Dag author having to know in advance how many tasks would be needed. |
| 25 | +Task mapping, also called dynamic task mapping, allows a way for a workflow to create a number of tasks at runtime based upon current data, rather than the Dag author having to know in advance how many tasks would be needed. |
25 | 26 |
|
26 | 27 | This is similar to defining your tasks in a for loop, but instead of having the DAG file fetch the data and do that itself, the scheduler can do this based on the output of an upstream task. |
27 | | -Unlike a Python for-loop executed at DAG parse time, dynamic task mapping defers task creation until runtime, allowing the scheduler to determine the exact number of task instances based on upstream task outputs. |
| 28 | +Unlike a Python for-loop executed at DAG parse time, task mapping defers task creation until runtime, allowing the scheduler to determine the exact number of task instances based on upstream task outputs. |
28 | 29 | Right before a mapped task is executed the scheduler will create *n* copies of the task, one for each input. |
29 | 30 |
|
30 | 31 | It is also possible to have a task operate on the collected output of a mapped task, commonly known as map and reduce. |
31 | 32 |
|
| 33 | +.. seealso:: |
| 34 | + Not sure whether you need mapped tasks or a loop? See :ref:`loops-and-mapped-tasks`. |
| 35 | + |
32 | 36 | Simple mapping |
33 | 37 | ============== |
34 | 38 |
|
35 | 39 | In its simplest form you can map over a list defined directly in your Dag file using the ``expand()`` function instead of calling your task directly. |
36 | 40 |
|
37 | | -If you want to see a simple usage of Dynamic Task Mapping, you can look below: |
| 41 | +If you want to see a simple usage of task mapping, you can look below: |
38 | 42 |
|
39 | 43 | .. exampleinclude:: /../src/airflow/example_dags/example_dynamic_task_mapping.py |
40 | 44 | :language: python |
@@ -388,7 +392,7 @@ For example, this code will *not* work: |
388 | 392 |
|
389 | 393 | When code in ``my_task_group`` is executed, ``value`` would still only be a reference, not the real value, so the ``if not value`` branch will not work as you likely want. However, if you pass that reference into a task, it will become resolved when the task is executed, and the three ``my_task`` instances will therefore receive 1, 2, and 3, respectively. |
390 | 394 |
|
391 | | -It is, therefore, important to remember that, if you intend to perform any logic on a value passed into a task group function, you must always use a task to run the logic, such as ``@task.branch`` (or ``BranchPythonOperator``) for conditions, and task mapping methods for loops. |
| 395 | +It is, therefore, important to remember that, if you intend to perform any logic on a value passed into a task group function, you must always use a task to run the logic, such as ``@task.branch`` (or ``BranchPythonOperator``) for conditions, and ``expand()`` to iterate over values. To repeat a group of tasks, see :ref:`loops-and-mapped-tasks`. |
392 | 396 |
|
393 | 397 | .. note:: Task-mapping in a mapped task group is not permitted |
394 | 398 |
|
|
0 commit comments