forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Datasets] Make Write op extend AbstractMap operator (ray-project#32538)
Signed-off-by: jianoaix <[email protected]>
- Loading branch information
Showing
7 changed files
with
121 additions
and
24 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
python/ray/data/_internal/logical/operators/write_operator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from ray.data._internal.logical.interfaces import LogicalOperator | ||
from ray.data._internal.logical.operators.map_operator import AbstractMap | ||
from ray.data.datasource.datasource import Datasource | ||
|
||
|
||
class Write(AbstractMap): | ||
"""Logical operator for write.""" | ||
|
||
def __init__( | ||
self, | ||
input_op: LogicalOperator, | ||
datasource: Datasource, | ||
ray_remote_args: Optional[Dict[str, Any]] = None, | ||
**write_args, | ||
): | ||
super().__init__( | ||
"Write", | ||
input_op, | ||
ray_remote_args, | ||
) | ||
self._datasource = datasource | ||
self._write_args = write_args | ||
# Always use task to write. | ||
self._compute = "tasks" | ||
# Take the input blocks unchanged while writing. | ||
self._target_block_size = float("inf") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Iterator | ||
|
||
from ray.data._internal.execution.interfaces import ( | ||
PhysicalOperator, | ||
TaskContext, | ||
) | ||
from ray.data._internal.execution.operators.map_operator import MapOperator | ||
from ray.data.block import Block | ||
from ray.data._internal.planner.write import generate_write_fn | ||
from ray.data._internal.logical.operators.write_operator import Write | ||
|
||
|
||
def _plan_write_op(op: Write, input_physical_dag: PhysicalOperator) -> PhysicalOperator: | ||
transform_fn = generate_write_fn(op._datasource, **op._write_args) | ||
|
||
def do_write(blocks: Iterator[Block], ctx: TaskContext) -> Iterator[Block]: | ||
yield from transform_fn(blocks, ctx) | ||
|
||
return MapOperator.create( | ||
do_write, | ||
input_physical_dag, | ||
name="Write", | ||
ray_remote_args=op._ray_remote_args, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
from typing import Callable, Iterator | ||
|
||
from ray.data._internal.execution.interfaces import TaskContext | ||
from ray.data.block import Block, RowUDF | ||
from ray.data.block import Block | ||
from ray.data.datasource import Datasource | ||
|
||
|
||
def generate_write_fn( | ||
datasource: Datasource, **write_args | ||
) -> Callable[[Iterator[Block], TaskContext, RowUDF], Iterator[Block]]: | ||
) -> Callable[[Iterator[Block], TaskContext], Iterator[Block]]: | ||
# If the write op succeeds, the resulting Dataset is a list of | ||
# WriteResult (one element per write task). Otherwise, an error will | ||
# be raised. The Datasource can handle execution outcomes with the | ||
# on_write_complete() and on_write_failed(). | ||
def fn(blocks: Iterator[Block], ctx, fn) -> Iterator[Block]: | ||
def fn(blocks: Iterator[Block], ctx) -> Iterator[Block]: | ||
return [[datasource.write(blocks, ctx, **write_args)]] | ||
|
||
return fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters