forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Data] Add
Datasource.on_write_start
(ray-project#38298)
Currently, we attempt to create a directory in every write task. This can cause rate limiting issues with S3. To address this problem, this PR adds a on_write_start method that is executed once per write job. Signed-off-by: Balaji Veeramani <[email protected]> Signed-off-by: e428265 <[email protected]>
- Loading branch information
1 parent
7c42912
commit 28ae7ad
Showing
5 changed files
with
107 additions
and
10 deletions.
There are no files selected for viewing
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
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
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,43 @@ | ||
import os | ||
|
||
import pyarrow | ||
import pytest | ||
|
||
import ray | ||
from ray.data.block import BlockAccessor | ||
from ray.data.datasource import FileBasedDatasource | ||
|
||
|
||
class MockFileBasedDatasource(FileBasedDatasource): | ||
def _write_block( | ||
self, f: "pyarrow.NativeFile", block: BlockAccessor, **writer_args | ||
): | ||
f.write(b"") | ||
|
||
|
||
@pytest.mark.parametrize("num_rows", [0, 1]) | ||
def test_write_preserves_user_directory(num_rows, tmp_path, ray_start_regular_shared): | ||
ds = ray.data.range(num_rows) | ||
path = os.path.join(tmp_path, "test") | ||
os.mkdir(path) # User-created directory | ||
|
||
ds.write_datasource(MockFileBasedDatasource(), dataset_uuid=ds._uuid, path=path) | ||
|
||
assert os.path.isdir(path) | ||
|
||
|
||
def test_write_creates_dir(tmp_path, ray_start_regular_shared): | ||
ds = ray.data.range(1) | ||
path = os.path.join(tmp_path, "test") | ||
|
||
ds.write_datasource( | ||
MockFileBasedDatasource(), dataset_uuid=ds._uuid, path=path, try_create_dir=True | ||
) | ||
|
||
assert os.path.isdir(path) | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
sys.exit(pytest.main(["-v", __file__])) |