Skip to content

[data] Add orc datasource for V2 - #64540

Closed
laysfire wants to merge 8 commits into
ray-project:masterfrom
laysfire:add_orcdatasource
Closed

laysfire wants to merge 8 commits into
ray-project:masterfrom
laysfire:add_orcdatasource

Conversation

@laysfire

@laysfire laysfire commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Support read orc format

Related issues

Link related issues: "Fixes #1234", "Closes #1234", or "Related to #1234".

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

@laysfire
laysfire requested a review from a team as a code owner July 6, 2026 03:31
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@laysfire

laysfire commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 a concrete DataSourceV2 implementation for ORC files (OrcDatasourceV2) with worker-side stripe chunking. It adds OrcFileChunker, OrcFileReader, OrcScanner, OrcInMemorySizeEstimator, and exposes the public read_orc API. Feedback on the implementation suggests optimizing the file reading loop in OrcFileReader by checking if the row limit has already been reached before opening subsequent files, thereby avoiding unnecessary I/O overhead.

Comment on lines +62 to +63
for path, chunk_metadatas in self._iter_contiguous_path_groups(input_split):
for table in self._read_path(path, chunk_metadatas):

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.

medium

To avoid unnecessary file opens and I/O overhead, we should check if the row limit has already been reached before calling _read_path for subsequent files in the outer loop.

Suggested change
for path, chunk_metadatas in self._iter_contiguous_path_groups(input_split):
for table in self._read_path(path, chunk_metadatas):
for path, chunk_metadatas in self._iter_contiguous_path_groups(input_split):
if self._limit is not None and rows_read >= self._limit:
return
for table in self._read_path(path, chunk_metadatas):

@laysfire laysfire changed the title [data] Add orcdatasource [data] Add orc datasource Jul 6, 2026
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Jul 6, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jul 20, 2026
@richardliaw richardliaw removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jul 20, 2026
@richardliaw richardliaw added the go add ONLY when ready to merge, run all tests label Jul 20, 2026
@laysfire
laysfire force-pushed the add_orcdatasource branch from 775827b to 82b21bf Compare July 27, 2026 08:58
@laysfire
laysfire requested a review from a team as a code owner July 28, 2026 02:47
@richardliaw

Copy link
Copy Markdown
Contributor

@laysfire thanks for the contribution. we're currently merging #37891 , which should be for V1. It'd be great to rebase on top of that when done.

@laysfire

Copy link
Copy Markdown
Contributor Author

@laysfire thanks for the contribution. we're currently merging #37891 , which should be for V1. It'd be great to rebase on top of that when done.

copy that. thanks for reply

@laysfire laysfire changed the title [data] Add orc datasource [data] Add orc datasource for V2 Aug 10, 2026
@richardliaw

Copy link
Copy Markdown
Contributor

@laysfire hey - we just merged the datasource for v1. Should we rebase and build off the current v1, pull out any shared utilities if needed?

Feel free to update the existing implementation in a way that makes sense

@laysfire

Copy link
Copy Markdown
Contributor Author

@laysfire hey - we just merged the datasource for v1. Should we rebase and build off the current v1, pull out any shared utilities if needed?

Feel free to update the existing implementation in a way that makes sense

Noted, Thanks

@laysfire

Copy link
Copy Markdown
Contributor Author

Current procedure is as following:

FileManifest row
        ↓
_get_fragments_to_read()
        ↓
_Fragment with offset
        ↓
FileReader._read_fragment_batches()
        |-- bounded concurrency
        |-- retry
        |-- ordering
        ↓
_iter_fragment_tables
        ↓
projection / partition columns / path / limit / stub column

The current PyArrow ORC FileFragment does not have a subset() or stripe sub-fragment API. The same pds.Fragment cannot express "read only the 3rd–5th stripe". Meanwhile, in order to reuse functions such as retry, ordering, projection, limit, and stub column from the base class filerreader.

Introduce _FragmentReadUnit, which combines:

  • A PyArrow file fragment
  • Its starting row offset within the source file

ORC extends this with _OrcReadUnit, which also carries stripe chunk metadata.

OrcFileReader only need to to override:

  • _get_fragments_to_read()
    Aggregate list rows by path and return _OrcReadUnit.
  • _iter_fragment_tables()
    Open the ORC file, parse the stripe range, and read/filter/complete/slice batches.

The common FileReader remains responsible for:

  • Bounded concurrent reads
  • Per-read-unit retries
  • Deterministic output handling
  • Row-offset bookkeeping
  • Limits
  • Partition and path columns
  • Final projection
  • Empty-projection stub columns

@ayushk7102 @richardliaw @goutamvenkat-anyscale @abhishekverma-ray Would you mind take a look?

Signed-off-by: yifan.xie <[email protected]>

@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 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit d4698c0. Configure here.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 4, 2026
goutamvenkat-anyscale pushed a commit that referenced this pull request Sep 18, 2026
## Why

`FileChunker` let a `FileIndexer` split one listed file into several
manifest rows. Nothing uses that seam any more: Parquet splits by row
group inside `FooterFileIndexer`'s footer read, every other indexer
emits one row per file, and `FilePartitioner` groups files into read
tasks. What remained was an abstract property every indexer had to
implement, a `WholeFileChunker` that returned its input unchanged, and a
`LineDelimitedFileChunker` with no callers outside its own tests.

First PR of the DSv2 reorg series; #66066 and the follow-ups will be
rebased onto it.

## What changes

- Delete `FileChunker`, `WholeFileChunker`, `LineDelimitedFileChunker`
and `LineDelimitedFileChunkMetadata`. The module keeps the manifest
metadata types (`ChunkMetadata`, `create_chunk_metadata`,
`ParquetRowGroupChunkMetadata`) that `OnlineBinPacker`,
`FooterFileIndexer` and `FileManifest` still use.
  Files: `datasource_v2/chunkers/file_chunker.py`
- `FileIndexer` drops the abstract `file_chunker` property.
`NonSamplingFileIndexer` drops the constructor argument and property,
and emits one manifest row per file with `None` chunk metadata.
  Files: `datasource_v2/listing/file_indexer.py`
- Remove two stale comments naming a `StreamingFileChunker` that never
existed.
Files: `datasource_v2/readers/parquet_file_reader.py`,
`logical/operators/read_operator.py`
- Tests: `test_file_chunker.py` becomes `test_chunk_metadata.py`
(metadata types only); chunker cases dropped from `test_file_indexer.py`
and `test_read_parquet_v2.py`.

## Example

Before, an indexer that lists whole files still had to answer the
chunker question:

```python
class MyIndexer(FileIndexer):
    @Property
    def file_chunker(self) -> FileChunker:   # required; always WholeFileChunker()
        return WholeFileChunker()

    def list_files(self, ctx): ...
```

After:

```python
class MyIndexer(FileIndexer):
    def list_files(self, ctx): ...
```

`read_parquet` behaviour is unchanged: `FooterFileIndexer` never used
the chunker it inherited. Net diff is +37 / −287 lines.

## Checks

Lint: ruff, ruff `--select I`, black, pydoclint with the CI flags, `git
diff --check`. Type check: pyrefly on `python/ray/data`, no errors in
the touched files.

Tests run locally:

```
pytest python/ray/data/tests/unit/datasource_v2                          # 217 passed
pytest python/ray/data/tests/datasource/test_read_parquet_v2.py          # 37 passed
pytest python/ray/data/tests/test_parquet.py                             # 246 passed, 13 skipped (34 pre-existing moto fixture errors)
pytest python/ray/data/tests/test_execution_optimizer_limit_pushdown.py  # 28 passed
pytest python/ray/data/tests/test_predicate_pushdown.py                  # 51 passed, 2 skipped
```

Not a duplicate: the only open PR mentioning `FileChunker` is #66066, my
own follow-up in this series. #64540 (ORC) adds an `OrcFileChunker` and
will need to drop it when it rebases.

Written with AI assistance (Claude Code). Every changed line was
reviewed by me and the tests above were run locally.

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

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Sep 19, 2026
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Why

`FileChunker` let a `FileIndexer` split one listed file into several
manifest rows. Nothing uses that seam any more: Parquet splits by row
group inside `FooterFileIndexer`'s footer read, every other indexer
emits one row per file, and `FilePartitioner` groups files into read
tasks. What remained was an abstract property every indexer had to
implement, a `WholeFileChunker` that returned its input unchanged, and a
`LineDelimitedFileChunker` with no callers outside its own tests.

First PR of the DSv2 reorg series; ray-project#66066 and the follow-ups will be
rebased onto it.

## What changes

- Delete `FileChunker`, `WholeFileChunker`, `LineDelimitedFileChunker`
and `LineDelimitedFileChunkMetadata`. The module keeps the manifest
metadata types (`ChunkMetadata`, `create_chunk_metadata`,
`ParquetRowGroupChunkMetadata`) that `OnlineBinPacker`,
`FooterFileIndexer` and `FileManifest` still use.
  Files: `datasource_v2/chunkers/file_chunker.py`
- `FileIndexer` drops the abstract `file_chunker` property.
`NonSamplingFileIndexer` drops the constructor argument and property,
and emits one manifest row per file with `None` chunk metadata.
  Files: `datasource_v2/listing/file_indexer.py`
- Remove two stale comments naming a `StreamingFileChunker` that never
existed.
Files: `datasource_v2/readers/parquet_file_reader.py`,
`logical/operators/read_operator.py`
- Tests: `test_file_chunker.py` becomes `test_chunk_metadata.py`
(metadata types only); chunker cases dropped from `test_file_indexer.py`
and `test_read_parquet_v2.py`.

## Example

Before, an indexer that lists whole files still had to answer the
chunker question:

```python
class MyIndexer(FileIndexer):
    @Property
    def file_chunker(self) -> FileChunker:   # required; always WholeFileChunker()
        return WholeFileChunker()

    def list_files(self, ctx): ...
```

After:

```python
class MyIndexer(FileIndexer):
    def list_files(self, ctx): ...
```

`read_parquet` behaviour is unchanged: `FooterFileIndexer` never used
the chunker it inherited. Net diff is +37 / −287 lines.

## Checks

Lint: ruff, ruff `--select I`, black, pydoclint with the CI flags, `git
diff --check`. Type check: pyrefly on `python/ray/data`, no errors in
the touched files.

Tests run locally:

```
pytest python/ray/data/tests/unit/datasource_v2                          # 217 passed
pytest python/ray/data/tests/datasource/test_read_parquet_v2.py          # 37 passed
pytest python/ray/data/tests/test_parquet.py                             # 246 passed, 13 skipped (34 pre-existing moto fixture errors)
pytest python/ray/data/tests/test_execution_optimizer_limit_pushdown.py  # 28 passed
pytest python/ray/data/tests/test_predicate_pushdown.py                  # 51 passed, 2 skipped
```

Not a duplicate: the only open PR mentioning `FileChunker` is ray-project#66066, my
own follow-up in this series. ray-project#64540 (ORC) adds an `OrcFileChunker` and
will need to drop it when it rebases.

Written with AI assistance (Claude Code). Every changed line was
reviewed by me and the tests above were run locally.

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

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
richardliaw pushed a commit that referenced this pull request Oct 15, 2026
## Description

This PR adds an internal ORC scanner and reader to DataSourceV2.
`OrcScanner` and `OrcFileReader` reuse `ArrowFileScanner` and
`FileReader` with PyArrow `OrcFileFormat` to scan whole-file fragments
in batches. They support column projection, Arrow-evaluated row filters,
limits, synthesized path/partition columns, and alignment to a supplied
schema (including nulls for missing file columns). `OrcFileReader`
retains Ray's pickled-object-column safety check. The PR also registers
`FileFormat.ORC` and adds direct `FileManifest` tests.

This PR also wires public `read_orc()` to `OrcDatasourceV2` through the
shared `DataContext.use_datasource_v2` flag, which defaults to true.
Setting it to false selects V1; `RAY_DATA_USE_DATASOURCE_V2` configures
the same flag. Path filtering via `partition_filter` is supported. The
datasource reuses generic file components and bounded schema sampling;
columns present only in files outside the sample may be omitted.
Stripe-level Ray task splitting and ORC-native predicate pruning remain
follow-up work; DataSourceV2 abstract interfaces are unchanged.

When partitioning is enabled in V2, directory values take precedence
over same-named file columns. Partition predicates prune known
nonmatching files before scanning; files with missing path keys retain
the complete read filter. Existing partition-directory validation
remains unchanged.

The related ORC V2 PR #64540 is closed and unmerged; it used the retired
`FileChunker` design. This implementation reuses the existing
`ArrowFileScanner` and `FileReader` interfaces.

## Related issues

Fixes #66526.

## Additional information

### Known limitations

ORC V2 shares two filtering issues with Parquet V2 in the common
file-reading path. Partition pruning can fail when parsed
partition-value types differ from the Dataset's logical schema, as
tracked in [#66915](#66915).
Expression filters on a synthesized `path` column can return incorrect
rows when a partition directory is also named `path`, or raise a
missing-field error without partitioning, as tracked in
[#66916](#66916). Both issues
are tracked separately and remain unresolved by this PR. Path selection
through `partition_filter` is distinct from expression filtering on the
synthesized `path` column.

### Validation

- `python -m pytest -q
python/ray/data/tests/unit/datasource_v2/test_orc_file_reader.py
python/ray/data/tests/unit/datasource_v2/test_orc_datasource_v2.py
python/ray/data/tests/unit/datasource/test_pickle_gate_coverage.py
python/ray/data/tests/unit/datasource_v2/test_file_scanner.py
python/ray/data/tests/unit/datasource_v2/test_derive_list_files_pushdown.py`
passed with Python 3.12.13 and PyArrow 23.0.1: 426 tests, with no
failures, errors, or skips.
- `python -m pytest -q python/ray/data/tests/datasource/test_orc.py`
passed with Python 3.12.13 and PyArrow 23.0.1: 149 tests covering V1/V2
public reads, partition handling, filtering, projection, limits, and ORC
read/write round trips, with no failures, errors, or skips.
- Pyrefly 0.51.0 checked all ORC implementation and test files: 0
errors.
- `python ci/pipeline/check-test-run.py` passed.
- Repository hooks passed for the changed files, including Ruff, Black,
pydoclint, AST, docstyle, and import checks.
- Semgrep checked `orc_scanner.py` and `test_orc_file_reader.py`: no
findings or errors.
- PyArrow 17 compatibility was verified for OrcFileFormat fragment
scanning, `batch_size`, `batch_readahead`, and missing-column null-fill
alignment.

PyArrow applies ORC row filters after reading selected columns; this PR
does not claim ORC-native stripe pruning or a fixed decoded-memory bound
from `batch_size`.

AI assistance was used: Codex helped implement the change and draft this
PR; Claude assisted with planning and code review.

---------

Signed-off-by: jiangxt2 <[email protected]>
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 go add ONLY when ready to merge, run all tests stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray fails to serialize self-reference objects

3 participants