Skip to content

[Data] Support PyArrow S3 storage options for file reads and writes - #68235

Open
dragongu wants to merge 4 commits into
ray-project:masterfrom
dragongu:data-s3-storage-options
Open

dragongu wants to merge 4 commits into
ray-project:masterfrom
dragongu:data-s3-storage-options

Conversation

@dragongu

Copy link
Copy Markdown
Contributor

Description

Add per-call storage_options to Ray Data's file read and write APIs to make S3 configuration easier: users can pass a dictionary instead of constructing and passing a PyArrow filesystem. Platform operators can centrally manage shared settings such as connect_timeout and request_timeout through DataContext.s3_filesystem_defaults or RAY_DATA_S3_FILESYSTEM_DEFAULTS, while users override only the settings they need.

Passing storage_options, including {}, applies these defaults; omitting it preserves existing filesystem inference. The shared resolver applies the configuration before listing or IO for V1 readers, Parquet/Text/ORC/MCAP V2 readers, and file datasinks.

@dragongu
dragongu requested review from a team as code owners November 17, 2026 06:43

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for passing PyArrow S3FileSystem keyword arguments via storage_options across Ray Data's file read and write APIs, and adds a s3_filesystem_defaults configuration to DataContext initialized from the RAY_DATA_S3_FILESYSTEM_DEFAULTS environment variable. Feedback on the changes highlights a security vulnerability where S3 URI credentials could be leaked in logs and dashboard paths, suggesting a reconstruction of the netloc without userinfo. Additionally, a robustness improvement is suggested to handle empty environment variables gracefully during JSON parsing to prevent import crashes.

Comment thread python/ray/data/datasource/path_util.py Resolved
Comment thread python/ray/data/context.py Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread python/ray/data/datasource/path_util.py Resolved
@dragongu
dragongu force-pushed the data-s3-storage-options branch from 8b772da to db0599a Compare November 17, 2026 06:48
@dragongu dragongu changed the title [Data] Support S3 storage options for file reads and writes [Data] Support PyArrow S3 storage options for file reads and writes Nov 17, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread python/ray/data/datasource/path_util.py Resolved
Forward per-call PyArrow S3FileSystem options through file-based readers
and writers, including the Parquet, Text, ORC and MCAP V2 readers.
Apply DataContext and environment defaults, then URI connection options,
then per-call overrides while preserving URI object paths.

Validate supported paths, argument types and filesystem/catalog conflicts,
and sanitize configuration errors without exposing credentials. Add
regression tests and document defaults and precedence.

Validation: applicable pre-commit checks passed. Isolated source tests
passed (46 cases, with Ray environment dependencies stubbed). Full Ray
pytest collection is blocked by the missing ray._raylet extension.

Signed-off-by: dragongu <[email protected]>
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Nov 17, 2026
Treat empty and whitespace-only RAY_DATA_S3_FILESYSTEM_DEFAULTS values as
unset, while still rejecting malformed nonempty JSON. Strip URI userinfo
before passing the object URI to any downstream path helper.

Add regressions for uppercase and percent-encoded URI credentials and
verify against a local S3 endpoint that anonymous@ requests remain
unsigned, matching PyArrow's native URI inference.

Validation: 56 isolated source test cases and applicable pre-commit checks
passed. Full Ray pytest collection remains blocked by missing ray._raylet.

Signed-off-by: dragongu <[email protected]>
@dragongu
dragongu force-pushed the data-s3-storage-options branch from db0599a to 5ca74c1 Compare November 17, 2026 07:17

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 5ca74c1. Configure here.

Comment thread python/ray/data/datasource/path_util.py Resolved
Comment thread python/ray/data/datasource/path_util.py Resolved
Remove custom S3 URI connection-option parsing and merging. Combine only
DataContext defaults and per-call storage_options, and let PyArrow's
S3FileSystem constructor validate the resulting keyword arguments.

Reject URI query parameters and userinfo when storage_options is supplied.
Keep the existing resolver behavior unchanged when storage_options is
omitted or an explicit filesystem is used. Update tests and documentation
to describe this narrower configuration boundary.

Validation: 65 isolated source cases passed on each of PyArrow 23.0.0 and
25.0.1; applicable pre-commit checks passed. Full Ray pytest collection
remains blocked by the missing ray._raylet extension.

Signed-off-by: dragongu <[email protected]>
@lhjnano

lhjnano commented Nov 17, 2026

Copy link
Copy Markdown

Related PR: #68208 (same issue #68206, read_parquet()-only scope). Your broader coverage across all read/write APIs plus s3_filesystem_defaults is a better fit. A few things worth folding in from ours:

  • s3a:// scheme support (Hadoop/Spark alias for S3)
  • Case-insensitive scheme matching (RFC 3986)
  • Root cause note: read_parquet() had no storage_options parameter, so the kwarg was silently absorbed by **ray_remote_args

Happy to help with the merge if useful.

Accept case-insensitive s3 and s3a URI prefixes in the storage_options
branch, using the same S3FileSystem and existing object-path normalization.
Keep the original inference and explicit-filesystem paths unchanged when
storage_options is omitted.

Cover mixed aliases, encoded object keys, credential forwarding, and local
HEAD/GET requests. Document that the alias support applies only when
storage_options is supplied.

Validation: 83 isolated source cases passed on each of PyArrow 23.0.0 and
25.0.1. Applicable pre-commit checks passed. Full Ray pytest collection
remains blocked by the missing ray._raylet extension.

Signed-off-by: dragongu <[email protected]>
@dragongu

Copy link
Copy Markdown
Contributor Author

Related PR: #68208 (same issue #68206, read_parquet()-only scope). Your broader coverage across all read/write APIs plus s3_filesystem_defaults is a better fit. A few things worth folding in from ours:

  • s3a:// scheme support (Hadoop/Spark alias for S3)
  • Case-insensitive scheme matching (RFC 3986)
  • Root cause note: read_parquet() had no storage_options parameter, so the kwarg was silently absorbed by **ray_remote_args

Happy to help with the merge if useful.

@lhjnano Thanks! s3a:// support and case-insensitive matching are now covered in 874b99e for the storage_options path. On the current base, the undeclared keyword went into **arrow_parquet_args, not **ray_remote_args. storage_options is now explicitly declared and forwarded to filesystem construction before listing.

@lhjnano

lhjnano commented Nov 19, 2026

Copy link
Copy Markdown

Since this supersedes #68208 and resolves #68206 for both reads and writes, adding Fixes #68206 to the description would auto-close the issue on merge.

richardliaw pushed a commit that referenced this pull request Nov 21, 2026
## Summary

Adds `python/ray/data/tests/AGENTS.md`, short instructions that tell
coding agents how to write Ray Data tests: shared cluster fixtures,
`DataContext` fixtures, test data, parametrize, asserts and mocks, plus
one before/after example. Recent agent-written Data PRs added 1.6× to
15× more test code than library code, much of it repeated setup: a Ray
cluster per test, a hand-set `DataContext`, field-by-field asserts.

It also adds one shared `datasource_v2` fixture to `tests/conftest.py`,
which the instructions point to. It replaces three copies of the same
fixture.

## Before

- No agent instructions say how to structure a Data test. #67919 (open)
adds rules on *which* tests to write, in
`python/ray/data/.claude/rules/`, which only Claude Code reads. #67928
(open) adds review instructions with one line on shared fixtures.
- Three copies of the V1/V2 reader fixture: `orc_reader_version` in
`test_orc.py`, `use_datasource_v2` in `test_parquet.py`, and an autouse
`datasource_v2` in `test_mcap.py`.

## After

- `python/ray/data/tests/AGENTS.md` holds the instructions. Codex,
Cursor and other agents read `AGENTS.md`;
`python/ray/data/tests/.claude/CLAUDE.md` imports it for Claude Code, as
`python/ray/data/` already does. The rules apply to new and changed
tests, not to rewriting untouched ones.
- One `datasource_v2` fixture in `tests/conftest.py`. `test_orc.py` and
`test_parquet.py` take it by name, and `test_mcap.py` applies it to
every test through `pytestmark`. Test ids (`[v1]`, `[v2]`) don't change.

No library code changes. The fixture change is a refactor: each file
collects the same tests as before.

## Subsystems

None. Tests and agent instructions only.

## Questions for reviewers

- @AarryaSaraf: this covers *how* to write tests, and your
`test_rules.md` in #67919 covers *which* tests to write. The PRs that
prompted this were written with Codex, which doesn't read
`.claude/rules/`. Would you be OK moving your test rules into this
`AGENTS.md`, here or in #67919, so every agent sees both?
- @goutamvenkat-anyscale: the fixture line in #67928's `REVIEW.md` could
link to this file.

## Additional information

### Not a duplicate

#67919 and #67928 are the only open PRs with agent rules for Data tests.
This PR covers what they don't: test structure and fixtures, in a file
that agents other than Claude Code also read.

### Testing

| Command | Result |
|---|---|
| pre-commit on the 6 changed files | Passed |
| `pytest datasource/test_mcap.py` | 67 passed, 6 skipped. The collected
test ids are identical to master's (73). |
| `pytest datasource/test_parquet.py -k "v1 or v2"` (the tests that use
the fixture) | 23 passed, 1 skipped |
| `pytest datasource/test_orc.py` | 217 passed, 6 failed: all
`test_read_orc_v2_partitioned_scan_optimizations`, which asserts the
reader's source path ends in `python/ray/data/...`. That isn't true for
the pip-installed Ray used locally, and the test doesn't use the renamed
fixture. |

Environment: Ray nightly (3eb9895) with this branch's
`python/ray/data` and `python/ray/tests` linked over it, Python 3.12.10,
pyarrow 23.0.1, pandas 2.3.3, pytest 7.4.4.

Not checked yet: that Codex and Claude Code load the new file when run
from the repository root.

### Note for open PRs

#68235 adds a test that takes `use_datasource_v2`. If it merges after
this PR, that test needs the one-word rename to `datasource_v2`.

AI assistance (Claude Code) was used to draft the instructions, the
fixture change and this description.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Abhishek Verma <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@iamjustinhsu

Copy link
Copy Markdown
Contributor

@dragongu can you help me understand the use case?

users can pass a dictionary instead of constructing and passing a PyArrow filesystem.

I see that this could be convenient, but don't think it adds too much value if we have 2 ways of doing the same thing. Does storage_options add more expressivity? I just wanna make sure this is the right use case because modifying the publicAPI is very hard to reverse, and will require other reviewers too

@dragongu

Copy link
Copy Markdown
Contributor Author

can you help me understand the use case?

users can pass a dictionary instead of constructing and passing a PyArrow filesystem.

I see that this could be convenient, but don't think it adds too much value if we have 2 ways of doing the same thing. Does storage_options add more expressivity? I just wanna make sure this is the right use case because modifying the publicAPI is very hard to reverse, and will require other reviewers too

@iamjustinhsu Thanks,here's how I think about it:

1. It follows the existing storage_options convention rather than adding a new one. Across Ray Data and the ecosystem, storage_options means "native options for the backend that actually does the IO": fsspec options in pandas and read_lerobot, hudi-rs options in read_hudi, Lance options in read_lance. Ray's file-based APIs do their IO through PyArrow filesystems, so here the options are pyarrow.fs.S3FileSystem keyword arguments. The docstrings say this explicitly so users don't expect fsspec key names.

2. What it adds beyond filesystem=: platform-level defaults. With filesystem=, every user has to build and configure their own filesystem object, so a platform team has no central place to enforce things like connect_timeout / request_timeout. DataContext.s3_filesystem_defaults (or RAY_DATA_S3_FILESYSTEM_DEFAULTS) lets operators set those once, and users only override what they need. filesystem= can't express that layering.

3. It fixes #68206. Today read_parquet(storage_options=...) is silently swallowed by **arrow_parquet_args, so options like endpoint_override are ignored and requests go to the wrong endpoint. Declaring the parameter makes it either take effect or fail loudly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants