Repository navigation
[release][Data] Cherry-pick "Fuse shuffle map with map op" (#68433) onto releases/2.61.0 - #68472
Conversation
## Description Lets the upstream read or map fuse into the disk-shuffle writer, so one task reads, maps, partitions and writes its shuffle file. Also set polars max threads in task instead of runtime env so shuffle map can fuse with other map op (or it'll blocked by different runtime env ) --------- Signed-off-by: You-Cheng Lin <[email protected]> (cherry picked from commit 1729626) Signed-off-by: elliot-barn <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request enables map fusion for disk-based hash shuffles by introducing the DiskShuffleMap logical operator and setting the Polars thread cap inside the task rather than via a runtime environment. This allows upstream reads and maps to fuse directly into the shuffle writer. However, a critical bug was identified in map_operator.py where the DiskShuffleMap class is defined in the middle of the AbstractMap class definition, which will break AbstractMap and its subclasses by incorrectly scoping subsequent methods.
| @dataclass(frozen=True, repr=False, eq=False, init=False) | ||
| class DiskShuffleMap(AbstractMap): | ||
| """Logical identity of a disk-shuffle writer (``plan_disk_hash_shuffle_map``). | ||
|
|
||
| The writer is a plain task-pool map, but the planner would tag it with the | ||
| shuffle's logical op (Repartition, Sort, Aggregate, Join), which map fusion | ||
| can't reason about. The plan function tags the writer with this op instead | ||
| so the upstream read or map fuses into it like into any other map. Not | ||
| user-facing: it never appears in a logical plan. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| name: str, | ||
| input_op: Optional[LogicalOperator], | ||
| ray_remote_args: Optional[Dict[str, Any]] = None, | ||
| ): | ||
| super().__init__( | ||
| name, | ||
| [input_op] if input_op is not None else [], | ||
| # The writer emits one handle row per task, unrelated to its input. | ||
| can_modify_num_rows=True, | ||
| ray_remote_args=ray_remote_args, | ||
| ) |
There was a problem hiding this comment.
Defining DiskShuffleMap at the module level here interrupts the class definition of AbstractMap. As a result, the subsequent _get_args method (and any other methods defined after it with 4-space indentation) will be incorrectly attached to DiskShuffleMap instead of AbstractMap. This will break all other subclasses of AbstractMap (such as MapBatches, Filter, FlatMap) because they will lose their _get_args implementation.\n\nPlease remove DiskShuffleMap from this position and define it at the end of the file (or at least after the full definition of AbstractMap is complete).
| @dataclass(frozen=True, repr=False, eq=False, init=False) | |
| class DiskShuffleMap(AbstractMap): | |
| """Logical identity of a disk-shuffle writer (``plan_disk_hash_shuffle_map``). | |
| The writer is a plain task-pool map, but the planner would tag it with the | |
| shuffle's logical op (Repartition, Sort, Aggregate, Join), which map fusion | |
| can't reason about. The plan function tags the writer with this op instead | |
| so the upstream read or map fuses into it like into any other map. Not | |
| user-facing: it never appears in a logical plan. | |
| """ | |
| def __init__( | |
| self, | |
| name: str, | |
| input_op: Optional[LogicalOperator], | |
| ray_remote_args: Optional[Dict[str, Any]] = None, | |
| ): | |
| super().__init__( | |
| name, | |
| [input_op] if input_op is not None else [], | |
| # The writer emits one handle row per task, unrelated to its input. | |
| can_modify_num_rows=True, | |
| ray_remote_args=ray_remote_args, | |
| ) | |
| \n |
Description
Cherry-pick of #68433 (
1729626bbb) ontoreleases/2.61.0. Lets the upstream read or map fuse into the disk-shuffle writer, and sets the polars thread limit inside the task rather than through the runtime env.The pick applied without conflicts. Seven master commits that touch the same files are not on the release branch (#67143, #68158, #68202 and its revert #68383, #68319, #67570, #68118), so the picked files differ from master in five places. Reviewers from Data, please confirm none of those is a prerequisite.
Testing
Ran locally against the
releases/2.61.0wheel (7c8ca5ea51) with the picked files overlaid:test_hash_shuffle_v2.py,test_operator_fusion.pyandtest_execution_optimizer_advanced.py, 232 passed, 2 skipped.🤖 Generated with Claude Code