Skip to content

[Data] DataSourceV2: row-group-aware Parquet chunking - #64301

Merged
goutamvenkat-anyscale merged 4 commits into
ray-project:masterfrom
abhishekverma-ray:dsv2-chunking-1-rowgroup-chunker
Jun 26, 2026
Merged

goutamvenkat-anyscale merged 4 commits into
ray-project:masterfrom
abhishekverma-ray:dsv2-chunking-1-rowgroup-chunker

Conversation

@abhishekverma-ray

Copy link
Copy Markdown
Contributor

Replaces the byte-estimate-and-reconcile Parquet chunker with one that reads the footer at listing time and chunks on true row-group boundaries.

Why

The Parquet read's atomic unit is the row group (PyArrow fragments are row-group-granular). The previous chunker estimated chunk count from ceil(file_size / target_chunk_size) and reconciled the guess to real row groups at read time. When the estimate diverged from the layout it produced empty read tasks and redundant footer reads — and misbehaved badly for large (128-512 MB) enterprise row groups, where a small target emitted hundreds of chunks for a file with 1-2 row groups.

What

  • ParquetFileChunker.generate_chunk_metadatas now reads each file's footer (pq.read_metadata) and greedily bundles consecutive row groups until their on-disk size reaches target_chunk_size (always

    = 1 row group per chunk). Each chunk carries an explicit half-open
    {row_group_start, row_group_end} range. Corrupt/unreadable footer or zero row groups falls back to a single whole-file chunk.

  • FileChunker gains a filesystem param on generate_chunk_metadatas and a reads_file_metadata flag.
  • NonSamplingFileIndexer threads the filesystem to the chunker and, when the chunker reads metadata, fans the footer reads across its thread pool over the discovered files (make_async_gen), so reads parallelize even for a single input directory. Pruning runs before chunking so footers are never read for files that would be discarded.
  • _fragments_from_chunk_metadata consumes the explicit range directly (defensive clamp to the file's actual row-group count); _calculate_row_group_range and the over-estimate→reconcile step are deleted.
  • The chunker's default target falls back to DataContext.target_min_block_size so normal-sized row groups map ~1:1 to chunks.

Replaces the interim adaptive byte-estimate path: removes read_api._compute_adaptive_parquet_chunk_size and the ParquetDatasourceV2._get_file_indexer(target_chunk_size_override=...) kwarg. F1 (num_buckets), F2 (partitioner), F4 (batch sizing), F5 (output block sizing) are unchanged.

Tests

  • test_file_chunker.py: footer-based bundling (K=1 when target < row-group size; bundle-all when target large), contiguous covering ranges, chunk_size == summed row-group bytes, corrupt-footer whole-file fallback, target resolution / precedence, reads_file_metadata flags.
  • test_parquet_datasource_v2.py: _fragments_from_chunk_metadata explicit-range slicing + defensive clamp; reader round-trips chunked manifests; deleted _calculate_row_group_range tests.
  • test_file_indexer.py: row-group-boundary splitting; parallel footer reads across workers.
  • test_read_api_parallelism.py: removed the deleted adaptive/override cases; kept F1/F4/F5 coverage.

Known limitation: a single-row-group file is still one read task (the inherent Parquet floor; sub-row-group reads are out of scope). Footer reads at listing scale with file count, parallelized across the indexer thread pool; read-time footer-read elimination (metadata caching) is a tracked follow-up.

@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 refactors the Parquet file chunking mechanism in Ray Data to chunk on true row-group boundaries by reading the Parquet footer at listing time. It updates the file indexer to parallelize footer reads and replaces estimated chunk indices with explicit row-group ranges. The feedback suggests using explicit 'is not None' checks instead of the 'or' operator when resolving configuration values to handle 0 correctly, and wrapping 'file_infos' with 'iter()' in 'make_async_gen' to ensure robustness when non-iterator iterables are passed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Jun 24, 2026
@@ -346,7 +303,8 @@ def test_parquet_file_reader_reads_chunked_manifest(tmp_path):
whole_tables = _read_via_reader(reader_whole, whole_manifest)
whole_rows = pa.concat_tables(whole_tables).column("id").to_pylist()

chunker = ParquetFileChunker(target_chunk_size=1024)
# target_chunk_size=1 forces one chunk per row group.
chunker = ParquetFileChunker(target_chunk_size=1)

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.

why are these tests being changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These tests cover the chunk-metadata → fragment-slicing path, and this PR changes the chunk-metadata schema. The old byte-estimate chunker emitted {chunk_idx, total_num_chunks} and the reader reconciled those to real row groups at read time via _calculate_row_group_range. This PR replaces that with explicit {row_group_start, row_group_end} ranges computed at listing time from the footer, and deletes the reconcile helper.

So the test changes are a 1:1 retarget to the new schema, not a coverage change:

removed test_calculate_row_group_range_distribution (and the _calculate_row_group_range import) since that helper no longer exists;
updated the fragment-slicing tests from chunk_idx/total_num_chunks to row_group_start/row_group_end (e.g. the old "out-of-range chunk → empty" case became test_fragments_from_chunk_metadata_clamps_range_beyond_row_groups, reflecting that an explicit range is clamped to the file's actual row-group count instead of being dropped).
Same intent (correct sub-fragment slicing + per-fragment row-hash offsets), expressed against the explicit-range metadata.

chunker = ParquetFileChunker(target_chunk_size=256 * 1024 * 1024)
chunks = list(
chunker.generate_chunk_metadatas("data.parquet", 100 * 1024 * 1024)
def test_reads_file_metadata_flag(self):

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.

Make the tests below here paramterized

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

abhishekverma-ray and others added 2 commits June 26, 2026 09:34
Replaces the byte-estimate-and-reconcile Parquet chunker with one that
reads the footer at listing time and chunks on true row-group
boundaries.

Why
---
The Parquet read's atomic unit is the row group (PyArrow fragments are
row-group-granular). The previous chunker estimated chunk count from
``ceil(file_size / target_chunk_size)`` and reconciled the guess to real
row groups at read time. When the estimate diverged from the layout it
produced empty read tasks and redundant footer reads — and misbehaved
badly for large (128-512 MB) enterprise row groups, where a small target
emitted hundreds of chunks for a file with 1-2 row groups.

What
----
- ``ParquetFileChunker.generate_chunk_metadatas`` now reads each file's
  footer (``pq.read_metadata``) and greedily bundles consecutive row
  groups until their on-disk size reaches ``target_chunk_size`` (always
  >= 1 row group per chunk). Each chunk carries an explicit half-open
  ``{row_group_start, row_group_end}`` range. Corrupt/unreadable footer
  or zero row groups falls back to a single whole-file chunk.
- ``FileChunker`` gains a ``filesystem`` param on
  ``generate_chunk_metadatas`` and a ``reads_file_metadata`` flag.
- ``NonSamplingFileIndexer`` threads the filesystem to the chunker and,
  when the chunker reads metadata, fans the footer reads across its
  thread pool over the *discovered files* (``make_async_gen``), so reads
  parallelize even for a single input directory. Pruning runs before
  chunking so footers are never read for files that would be discarded.
- ``_fragments_from_chunk_metadata`` consumes the explicit range
  directly (defensive clamp to the file's actual row-group count);
  ``_calculate_row_group_range`` and the over-estimate→reconcile step are
  deleted.
- The chunker's default target falls back to
  ``DataContext.target_min_block_size`` so normal-sized row groups map
  ~1:1 to chunks.

Replaces the interim adaptive byte-estimate path: removes
``read_api._compute_adaptive_parquet_chunk_size`` and the
``ParquetDatasourceV2._get_file_indexer(target_chunk_size_override=...)``
kwarg. F1 (num_buckets), F2 (partitioner), F4 (batch sizing), F5 (output
block sizing) are unchanged.

Tests
-----
- ``test_file_chunker.py``: footer-based bundling (K=1 when target <
  row-group size; bundle-all when target large), contiguous covering
  ranges, chunk_size == summed row-group bytes, corrupt-footer
  whole-file fallback, target resolution / precedence,
  ``reads_file_metadata`` flags.
- ``test_parquet_datasource_v2.py``: ``_fragments_from_chunk_metadata``
  explicit-range slicing + defensive clamp; reader round-trips chunked
  manifests; deleted ``_calculate_row_group_range`` tests.
- ``test_file_indexer.py``: row-group-boundary splitting; parallel
  footer reads across workers.
- ``test_read_api_parallelism.py``: removed the deleted
  adaptive/override cases; kept F1/F4/F5 coverage.

Known limitation: a single-row-group file is still one read task (the
inherent Parquet floor; sub-row-group reads are out of scope). Footer
reads at listing scale with file count, parallelized across the indexer
thread pool; read-time footer-read elimination (metadata caching) is a
tracked follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
- ParquetFileChunker target resolution: use explicit ``is not None`` checks
  instead of ``or`` so an explicit ``0`` isn't coalesced away as "unset".
- file_indexer: wrap the ``make_async_gen`` base_iterator in ``iter()`` so a
  non-iterator iterable (e.g. a list in tests/subclasses) is consumed correctly.
- test_file_chunker: parametrize the row-group bundling and target-resolution
  tests (adds an explicit-0 case that covers the resolution fix).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray
abhishekverma-ray force-pushed the dsv2-chunking-1-rowgroup-chunker branch from 2bad95c to 88e7104 Compare June 26, 2026 04:05

@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 88e7104. Configure here.

…king

make_async_gen only preserves ordering for a 1:1 map, but the per-file chunker
is 1:N, so its round-robin merge interleaved chunks across the files processed
concurrently -- breaking per-file contiguity / discovery order under
preserve_order=True. (No data-correctness impact: chunks carry explicit
row-group ranges and per-chunk row-hash offsets, both order-independent.)

Emit one record list per file (1:1) and flatten on consume, so footer reads
still parallelize but ordering is preserved. Adds a regression test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@goutamvenkat-anyscale goutamvenkat-anyscale added the go add ONLY when ready to merge, run all tests label Jun 26, 2026
The V2 test files under tests/unit/datasource_v2/ and
_internal/datasource_v2/tests/ were never added to pyrefly-excluded-files.txt,
unlike every other Ray Data test file. pyrefly therefore type-checked them and
flagged TypedDict-subscript / Optional-access patterns in the tests. Exclude
them to match the repo convention that tests are not type-checked.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 6627f78 into ray-project:master Jun 26, 2026
3 checks passed
abhishekverma-ray added a commit to abhishekverma-ray/ray-dev-abhishek that referenced this pull request Jun 29, 2026
Builds on the row-group-aware Parquet chunker (PR ray-project#64301). Surviving
read-path fixes from the dsv2-chunking experiments:

- FileAffinityPartitioner (new default): keeps a file's chunks in that file's
  own size-bounded partitions (locality + sub-file parallelism); round-robin
  retained behind DataContext.partitioner_strategy. The partitioner orders a
  file's chunks by the right positional key for every chunk-metadata schema
  (row-group index / line-delimited byte offset / legacy chunk index).
- Dedicated sizing knobs shipping a throughput+locality default profile:
  partitioner_max_bucket_size_bytes (1 GiB),
  parquet_reader_max_coalesced_scan_bytes (1 GiB), and
  parquet_reader_target_batch_size_bytes (128 MiB). The partitioner knobs are
  format-agnostic (no parquet_ prefix); the reader/scan knobs are Parquet-
  specific. The 1 GiB partitions bundle consecutive row groups into fewer,
  file-local read tasks; the 128 MiB decode batch streams the partition instead
  of holding it whole (set any knob to None to fall back to the block-size
  knobs).
- Reader coalesces a partition's contiguous row groups into one scan (one open +
  cached footer + sequential I/O), split by the per-scan on-disk cap to bound the
  pre_buffer footprint.
- Per-task fragment-read concurrency keyed on the distinct file count
  (read_files_num_threads=2 / arrow_scanner_batch_readahead=4), so same-file
  sub-scans stay sequential and per-task decoded memory stays bounded
  (~512 MiB in flight per scan).
- Constant-ratio in-memory partition sizing (the footer-derived estimator
  experiment was removed).

Tests updated/added across the chunker, partitioner, reader, and context.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
abhishekverma-ray added a commit to abhishekverma-ray/ray-dev-abhishek that referenced this pull request Jun 30, 2026
Surviving read-path work from the dsv2-chunking experiments, built on the
row-group-aware Parquet chunker (PR ray-project#64301):

- FileAffinityPartitioner (the V2 default): keeps a file's chunks in that
  file's own size-bounded partitions -- one file per read task (locality:
  one open + one footer + sequential I/O) with sub-file parallelism for large
  files. Reuses the shared ``_WeightedBucket`` primitive.
- Footer-derived, type-aware in-memory size estimate: the chunker reads the
  footer at listing time and stamps each chunk's decoded Arrow size onto its
  metadata (fixed-width columns sized exactly from their type; variable-width
  via the footer's uncompressed bytes x ``parquet_in_memory_var_width_factor``).
  The partitioner sizes partitions by this real footprint instead of a flat
  on-disk x5 ratio, and falls back to the ratio per chunk when no footer hint
  exists (corrupt footer / non-Parquet).
- Reader coalesces a partition's contiguous row groups into one scan (one open
  + cached footer + sequential I/O) instead of one scan per row group; per-task
  fragment-read concurrency keys on the distinct file count so same-file
  sub-scans stay sequential and per-task decoded memory stays bounded.
- Dedicated sizing knobs: ``partitioner_max_bucket_size_bytes`` (1 GiB),
  ``parquet_reader_target_batch_size_bytes`` (128 MiB),
  ``parquet_in_memory_var_width_factor`` (2.0); ``read_files_num_threads`` (2)
  / ``arrow_scanner_batch_readahead`` (4).

Tests across the chunker, partitioner, reader, estimator, and context.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
abhishekverma-ray added a commit to abhishekverma-ray/ray-dev-abhishek that referenced this pull request Jun 30, 2026
Surviving read-path work from the dsv2-chunking experiments, built on the
row-group-aware Parquet chunker (PR ray-project#64301):

- FileAffinityPartitioner (the V2 default): keeps a file's chunks in that
  file's own size-bounded partitions -- one file per read task (locality:
  one open + one footer + sequential I/O) with sub-file parallelism for large
  files. Reuses the shared ``_WeightedBucket`` primitive.
- Footer-derived, type-aware in-memory size estimate: the chunker reads the
  footer at listing time and stamps each chunk's decoded Arrow size onto its
  metadata (fixed-width columns sized exactly from their type; variable-width
  via the footer's uncompressed bytes x ``parquet_in_memory_var_width_factor``).
  The partitioner sizes partitions by this real footprint instead of a flat
  on-disk x5 ratio, and falls back to the ratio per chunk when no footer hint
  exists (corrupt footer / non-Parquet).
- Reader coalesces a partition's contiguous row groups into one scan (one open
  + cached footer + sequential I/O) instead of one scan per row group; per-task
  fragment-read concurrency keys on the distinct file count so same-file
  sub-scans stay sequential and per-task decoded memory stays bounded.
- Dedicated sizing knobs: ``partitioner_max_bucket_size_bytes`` (1 GiB),
  ``parquet_reader_target_batch_size_bytes`` (128 MiB),
  ``parquet_in_memory_var_width_factor`` (2.0); ``read_files_num_threads`` (2)
  / ``arrow_scanner_batch_readahead`` (4).

Tests across the chunker, partitioner, reader, estimator, and context.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
abhishekverma-ray added a commit to abhishekverma-ray/ray-dev-abhishek that referenced this pull request Jun 30, 2026
Surviving read-path work from the dsv2-chunking experiments, built on the
row-group-aware Parquet chunker (PR ray-project#64301):

- FileAffinityPartitioner (the V2 default): keeps a file's chunks in that
  file's own size-bounded partitions -- one file per read task (locality:
  one open + one footer + sequential I/O) with sub-file parallelism for large
  files. Reuses the shared ``_WeightedBucket`` primitive.
- Footer-derived, type-aware in-memory size estimate: the chunker reads the
  footer at listing time and stamps each chunk's decoded Arrow size onto its
  metadata (fixed-width columns sized exactly from their type; variable-width
  via the footer's uncompressed bytes x ``parquet_in_memory_var_width_factor``).
  The partitioner sizes partitions by this real footprint instead of a flat
  on-disk x5 ratio, and falls back to the ratio per chunk when no footer hint
  exists (corrupt footer / non-Parquet).
- Reader coalesces a partition's contiguous row groups into one scan (one open
  + cached footer + sequential I/O) instead of one scan per row group; per-task
  fragment-read concurrency keys on the distinct file count so same-file
  sub-scans stay sequential and per-task decoded memory stays bounded.
- Dedicated sizing knobs: ``partitioner_max_bucket_size_bytes`` (1 GiB),
  ``parquet_reader_target_batch_size_bytes`` (128 MiB),
  ``parquet_in_memory_var_width_factor`` (2.0); ``read_files_num_threads`` (2)
  / ``arrow_scanner_batch_readahead`` (4).

Tests across the chunker, partitioner, reader, estimator, and context.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
)

Replaces the byte-estimate-and-reconcile Parquet chunker with one that
reads the footer at listing time and chunks on true row-group
boundaries.

Why
---
The Parquet read's atomic unit is the row group (PyArrow fragments are
row-group-granular). The previous chunker estimated chunk count from
``ceil(file_size / target_chunk_size)`` and reconciled the guess to real
row groups at read time. When the estimate diverged from the layout it
produced empty read tasks and redundant footer reads — and misbehaved
badly for large (128-512 MB) enterprise row groups, where a small target
emitted hundreds of chunks for a file with 1-2 row groups.

What
----
- ``ParquetFileChunker.generate_chunk_metadatas`` now reads each file's
footer (``pq.read_metadata``) and greedily bundles consecutive row
groups until their on-disk size reaches ``target_chunk_size`` (always
  >= 1 row group per chunk). Each chunk carries an explicit half-open
``{row_group_start, row_group_end}`` range. Corrupt/unreadable footer or
zero row groups falls back to a single whole-file chunk.
- ``FileChunker`` gains a ``filesystem`` param on
``generate_chunk_metadatas`` and a ``reads_file_metadata`` flag.
- ``NonSamplingFileIndexer`` threads the filesystem to the chunker and,
when the chunker reads metadata, fans the footer reads across its thread
pool over the *discovered files* (``make_async_gen``), so reads
parallelize even for a single input directory. Pruning runs before
chunking so footers are never read for files that would be discarded.
- ``_fragments_from_chunk_metadata`` consumes the explicit range
directly (defensive clamp to the file's actual row-group count);
``_calculate_row_group_range`` and the over-estimate→reconcile step are
deleted.
- The chunker's default target falls back to
``DataContext.target_min_block_size`` so normal-sized row groups map
~1:1 to chunks.

Replaces the interim adaptive byte-estimate path: removes
``read_api._compute_adaptive_parquet_chunk_size`` and the
``ParquetDatasourceV2._get_file_indexer(target_chunk_size_override=...)``
kwarg. F1 (num_buckets), F2 (partitioner), F4 (batch sizing), F5 (output
block sizing) are unchanged.

Tests
-----
- ``test_file_chunker.py``: footer-based bundling (K=1 when target <
row-group size; bundle-all when target large), contiguous covering
ranges, chunk_size == summed row-group bytes, corrupt-footer whole-file
fallback, target resolution / precedence, ``reads_file_metadata`` flags.
- ``test_parquet_datasource_v2.py``: ``_fragments_from_chunk_metadata``
explicit-range slicing + defensive clamp; reader round-trips chunked
manifests; deleted ``_calculate_row_group_range`` tests.
- ``test_file_indexer.py``: row-group-boundary splitting; parallel
footer reads across workers.
- ``test_read_api_parallelism.py``: removed the deleted
adaptive/override cases; kept F1/F4/F5 coverage.

Known limitation: a single-row-group file is still one read task (the
inherent Parquet floor; sub-row-group reads are out of scope). Footer
reads at listing scale with file count, parallelized across the indexer
thread pool; read-time footer-read elimination (metadata caching) is a
tracked follow-up.

---------

Signed-off-by: Abhishek Verma <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
abhishekverma-ray added a commit to abhishekverma-ray/ray-dev-abhishek that referenced this pull request Jul 1, 2026
Surviving read-path work from the dsv2-chunking experiments, built on the
row-group-aware Parquet chunker (PR ray-project#64301):

- FileAffinityPartitioner (the V2 default): keeps a file's chunks in that
  file's own size-bounded partitions -- one file per read task (locality:
  one open + one footer + sequential I/O) with sub-file parallelism for large
  files. Reuses the shared ``_WeightedBucket`` primitive.
- Footer-derived, type-aware in-memory size estimate: the chunker reads the
  footer at listing time and stamps each chunk's decoded Arrow size onto its
  metadata (fixed-width columns sized exactly from their type; variable-width
  via the footer's uncompressed bytes x ``parquet_in_memory_var_width_factor``).
  The partitioner sizes partitions by this real footprint instead of a flat
  on-disk x5 ratio, and falls back to the ratio per chunk when no footer hint
  exists (corrupt footer / non-Parquet).
- Reader coalesces a partition's contiguous row groups into one scan (one open
  + cached footer + sequential I/O) instead of one scan per row group; per-task
  fragment-read concurrency keys on the distinct file count so same-file
  sub-scans stay sequential and per-task decoded memory stays bounded.
- Dedicated sizing knobs: ``partitioner_max_bucket_size_bytes`` (1 GiB),
  ``parquet_reader_target_batch_size_bytes`` (128 MiB),
  ``parquet_in_memory_var_width_factor`` (2.0); ``read_files_num_threads`` (2)
  / ``arrow_scanner_batch_readahead`` (4).

Tests across the chunker, partitioner, reader, estimator, and context.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
abhishekverma-ray added a commit to abhishekverma-ray/ray-dev-abhishek that referenced this pull request Jul 7, 2026
Surviving read-path work from the dsv2-chunking experiments, built on the
row-group-aware Parquet chunker (PR ray-project#64301):

- FileAffinityPartitioner (the V2 default): keeps a file's chunks in that
  file's own size-bounded partitions -- one file per read task (locality:
  one open + one footer + sequential I/O) with sub-file parallelism for large
  files. Reuses the shared ``_WeightedBucket`` primitive.
- Footer-derived, type-aware in-memory size estimate: the chunker reads the
  footer at listing time and stamps each chunk's decoded Arrow size onto its
  metadata (fixed-width columns sized exactly from their type; variable-width
  via the footer's uncompressed bytes x ``parquet_in_memory_var_width_factor``).
  The partitioner sizes partitions by this real footprint instead of a flat
  on-disk x5 ratio, and falls back to the ratio per chunk when no footer hint
  exists (corrupt footer / non-Parquet).
- Reader coalesces a partition's contiguous row groups into one scan (one open
  + cached footer + sequential I/O) instead of one scan per row group; per-task
  fragment-read concurrency keys on the distinct file count so same-file
  sub-scans stay sequential and per-task decoded memory stays bounded.
- Dedicated sizing knobs: ``partitioner_max_bucket_size_bytes`` (1 GiB),
  ``parquet_reader_target_batch_size_bytes`` (128 MiB),
  ``parquet_in_memory_var_width_factor`` (2.0); ``read_files_num_threads`` (2)
  / ``arrow_scanner_batch_readahead`` (4).

Tests across the chunker, partitioner, reader, estimator, and context.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
abhishekverma-ray added a commit to abhishekverma-ray/ray-dev-abhishek that referenced this pull request Jul 8, 2026
Surviving read-path work from the dsv2-chunking experiments, built on the
row-group-aware Parquet chunker (PR ray-project#64301):

- FileAffinityPartitioner (the V2 default): keeps a file's chunks in that
  file's own size-bounded partitions -- one file per read task (locality:
  one open + one footer + sequential I/O) with sub-file parallelism for large
  files. Reuses the shared ``_WeightedBucket`` primitive.
- Footer-derived, type-aware in-memory size estimate: the chunker reads the
  footer at listing time and stamps each chunk's decoded Arrow size onto its
  metadata (fixed-width columns sized exactly from their type; variable-width
  via the footer's uncompressed bytes x ``parquet_in_memory_var_width_factor``).
  The partitioner sizes partitions by this real footprint instead of a flat
  on-disk x5 ratio, and falls back to the ratio per chunk when no footer hint
  exists (corrupt footer / non-Parquet).
- Reader coalesces a partition's contiguous row groups into one scan (one open
  + cached footer + sequential I/O) instead of one scan per row group; per-task
  fragment-read concurrency keys on the distinct file count so same-file
  sub-scans stay sequential and per-task decoded memory stays bounded.
- Dedicated sizing knobs: ``partitioner_max_bucket_size_bytes`` (1 GiB),
  ``parquet_reader_target_batch_size_bytes`` (128 MiB),
  ``parquet_in_memory_var_width_factor`` (2.0); ``read_files_num_threads`` (2)
  / ``arrow_scanner_batch_readahead`` (4).

Tests across the chunker, partitioner, reader, estimator, and context.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
goutamvenkat-anyscale added a commit that referenced this pull request Jul 16, 2026
Reverts #64301

---------

Signed-off-by: Goutam <[email protected]>
Co-authored-by: Goutam <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
AarryaSaraf added a commit to AarryaSaraf/ray that referenced this pull request Aug 1, 2026
The native chunked-read path read `chunk_metadata["row_group_start"]` /
`["row_group_end"]` — keys from the row-group-aware chunker (PR ray-project#64301) that
was reverted upstream (PR ray-project#64541). The current `ParquetFileChunker` emits a
relative `(chunk_idx, total_num_chunks)` descriptor and defers row-group
resolution to read time, so any chunked read raised `KeyError: 'row_group_start'`
(seen in the `read_large_parquet` release tests).

Resolve the descriptor with the same `_calculate_row_group_range` helper the
PyArrow reader uses, in both `_native_fragments_for_file` and
`_native_count_fragments`, so native fragments line up byte-for-byte with the
PyArrow path (identical row_hash offsets and limit slicing) and the
planner-over-estimated case (`None`) is handled. Update
`test_native_chunked_read_row_hash_parity` to build metadata with the real
schema; validated end-to-end that the chunked native read matches PyArrow.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
AarryaSaraf added a commit to AarryaSaraf/ray that referenced this pull request Aug 1, 2026
test_chunker_native_metadata_matches_pyarrow and
test_chunker_native_metadata_makes_no_pyarrow_footer_read asserted that the
ParquetFileChunker reads Parquet footers through the native crate at chunk
time — a capability from the row-group-aware chunker (PR ray-project#64301) that was
reverted upstream (PR ray-project#64541). The current chunker splits by byte size and
reads no footer during chunking, so both tests reference a dead
generate_chunk_metadatas(path, size, fs) signature and dead metadata keys.
The reader's own native footer read stays covered by
test_native_read_is_pyarrow_free.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
)

Replaces the byte-estimate-and-reconcile Parquet chunker with one that
reads the footer at listing time and chunks on true row-group
boundaries.

Why
---
The Parquet read's atomic unit is the row group (PyArrow fragments are
row-group-granular). The previous chunker estimated chunk count from
``ceil(file_size / target_chunk_size)`` and reconciled the guess to real
row groups at read time. When the estimate diverged from the layout it
produced empty read tasks and redundant footer reads — and misbehaved
badly for large (128-512 MB) enterprise row groups, where a small target
emitted hundreds of chunks for a file with 1-2 row groups.

What
----
- ``ParquetFileChunker.generate_chunk_metadatas`` now reads each file's
footer (``pq.read_metadata``) and greedily bundles consecutive row
groups until their on-disk size reaches ``target_chunk_size`` (always
  >= 1 row group per chunk). Each chunk carries an explicit half-open
``{row_group_start, row_group_end}`` range. Corrupt/unreadable footer or
zero row groups falls back to a single whole-file chunk.
- ``FileChunker`` gains a ``filesystem`` param on
``generate_chunk_metadatas`` and a ``reads_file_metadata`` flag.
- ``NonSamplingFileIndexer`` threads the filesystem to the chunker and,
when the chunker reads metadata, fans the footer reads across its thread
pool over the *discovered files* (``make_async_gen``), so reads
parallelize even for a single input directory. Pruning runs before
chunking so footers are never read for files that would be discarded.
- ``_fragments_from_chunk_metadata`` consumes the explicit range
directly (defensive clamp to the file's actual row-group count);
``_calculate_row_group_range`` and the over-estimate→reconcile step are
deleted.
- The chunker's default target falls back to
``DataContext.target_min_block_size`` so normal-sized row groups map
~1:1 to chunks.

Replaces the interim adaptive byte-estimate path: removes
``read_api._compute_adaptive_parquet_chunk_size`` and the
``ParquetDatasourceV2._get_file_indexer(target_chunk_size_override=...)``
kwarg. F1 (num_buckets), F2 (partitioner), F4 (batch sizing), F5 (output
block sizing) are unchanged.

Tests
-----
- ``test_file_chunker.py``: footer-based bundling (K=1 when target <
row-group size; bundle-all when target large), contiguous covering
ranges, chunk_size == summed row-group bytes, corrupt-footer whole-file
fallback, target resolution / precedence, ``reads_file_metadata`` flags.
- ``test_parquet_datasource_v2.py``: ``_fragments_from_chunk_metadata``
explicit-range slicing + defensive clamp; reader round-trips chunked
manifests; deleted ``_calculate_row_group_range`` tests.
- ``test_file_indexer.py``: row-group-boundary splitting; parallel
footer reads across workers.
- ``test_read_api_parallelism.py``: removed the deleted
adaptive/override cases; kept F1/F4/F5 coverage.

Known limitation: a single-row-group file is still one read task (the
inherent Parquet floor; sub-row-group reads are out of scope). Footer
reads at listing scale with file count, parallelized across the indexer
thread pool; read-time footer-read elimination (metadata caching) is a
tracked follow-up.

---------

Signed-off-by: Abhishek Verma <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…roject#64541)

Reverts ray-project#64301

---------

Signed-off-by: Goutam <[email protected]>
Co-authored-by: Goutam <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants