Skip to content

[Data] Iceberg DSv2 [4/15]: Size Parquet files with the decoded-size estimator and request their decode memory - #68438

Draft
AarryaSaraf wants to merge 2 commits into
iceberg-dsv2-parity-5-countfrom
iceberg-decoded-size
Draft

AarryaSaraf wants to merge 2 commits into
iceberg-dsv2-parity-5-countfrom
iceberg-decoded-size

Conversation

@AarryaSaraf

@AarryaSaraf AarryaSaraf commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Sizes each Iceberg Parquet file at its estimated decoded bytes, read from its footer with Ray's Parquet decoded-size estimator. Each read task then requests its files' summed decode memory, as Parquet V2 reads do with #67839, #67840 and #67841. 4 of 15 in the stack moving read_iceberg onto Datasource V2 (#66181), on top of [3/15].

Review only the second commit. The first commit is #67839, #67840 and #67841 squashed (at 4e2dab4798). It is here only so this branch builds, and it goes away once those PRs merge. On top of them, it gives _get_file_indexer the schema argument that #67840 adds to every datasource in the sources #67840 doesn't have yet: Iceberg's, and the CSV, JSON and Delta V2 sources that reached master after 4e2dab4798. Without those, read_csv, read_json and Delta V2 reads raise TypeError once #67840 passes schema. If #67840 merges before [2/15], [2/15] has to add Iceberg's instead.

Before

Each file is sized at file_size_in_bytes: the whole file, all columns, compressed. So a 128 MiB task holds several times that once decoded, and a one-column read of a wide table is sized as if it read every column. Iceberg's metadata can't do better: per file it records only file_size_in_bytes and per-column column_sizes, both compressed bytes on disk, with no uncompressed or decoded size. Read tasks request no memory.

After

  1. Footer sizing. Files: _internal/datasource_v2/formats/iceberg/iceberg_footer_sizing.py (new), iceberg_file_indexer.py, iceberg_manifest.py.
    • After plan_files(), the listing task runs Parquet's FooterFileIndexer over the planned Parquet files: one footer read per file. That gives each row group's decoded bytes and decode peak for the columns read.
    • Each file's row groups are summed into one whole-file chunk (size_bytes, memory_bytes). OnlineBinPacker packs on size_bytes, and [Data] Request each Parquet read task's estimated decode peak as its logical memory [6/6] #67841 turns a task's summed memory_bytes into its memory request.
    • A file is sized this way when all of these hold:
      • The table's FileIO is PyArrowFileIO.
      • The read is case-sensitive and reads at least one column.
      • The table has no name mapping.
      • No column read was ever stored under another name.
      • The file is Parquet and lives on the table's filesystem.
    • Every other file keeps its on-disk size and requests no memory.
  2. count() reads no footer. Files: iceberg_file_indexer.py. as_whole_file_indexer now returns a copy with footer reads off (reads_footers=False), because Ray's count rule allows no per-file IO while listing.
  3. The listing honors selected_fields. Files: iceberg_datasource_v2.py, iceberg_file_indexer.py. The listing scan now projects read_iceberg's selected_fields, so sizes are for the columns actually read.

On the test table, every file's estimate equals its real decoded size: 33–54 B per file, each equal to pq.ParquetFile(path).read(columns=["col_a"]).nbytes. The decode memory is 2,520–2,671 B per file.

Cost: the listing task reads one footer per Parquet file before it emits the first manifest. Parquet's own reader does the same. I haven't measured it on a large table.

flowchart TD
    subgraph Before
        subgraph BS["Subsystem: IO (formats/iceberg/)"]
            B1["plan_files()"] --> B2["manifest row<br/>size = file_size_in_bytes"] --> B3["OnlineBinPacker"] --> B4["read task, no memory request"]
        end
    end
    subgraph After
        subgraph AS["Subsystem: IO (formats/iceberg/)"]
            A1["plan_files()"] --> A2["IcebergFooterSizing<br/>FooterFileIndexer: one footer read per Parquet file"]
            A2 --> A3["manifest row<br/>size_bytes = decoded bytes, memory_bytes = decode peak"]
            A3 --> A4["OnlineBinPacker"] --> A5["read task requests summed memory_bytes (#67841)"]
        end
    end
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    class A2 added
    class A3,A5 changed
Loading

Subsystems

IO (formats/iceberg/). The memory request itself is #67841's change to resource allocation.

Testing

pytest python/ray/data/tests/datasource/test_iceberg.py: 157 passed, 6 skipped at this PR's head (pyarrow 24.0.0, PyIceberg 0.11.1). The new tests check three things:

  • a Parquet file's size equals its decoded bytes, and its memory is larger;
  • a renamed column falls back to the on-disk size with no memory;
  • a packed read task carries its files' summed memory.

ruff 0.8.4 (default and --select I), black 22.10.0, pydoclint 0.9.1 and pyrefly 0.51.0 (CI's environment) are clean. #67839–#67841's own tests are in those PRs.

Not a duplicate: apart from this stack, no open PR moves read_iceberg to Datasource V2. I searched open PRs with "iceberg" in the title on 2026-11-21; the only other one, #68252, fixes Iceberg writes on actor pools.

AI assistance (Claude Code) was used. I have reviewed every changed line and ran the tests above locally.

Signed-off-by: Aarrya [email protected]

🤖 Generated with Claude Code

@AarryaSaraf
AarryaSaraf added this pull request to stack #68450 November 21, 2026 23:17
AarryaSaraf and others added 2 commits November 23, 2026 16:35
#67841 at 4e2dab4), with every _get_file_indexer, including Iceberg's and master's CSV, JSON and Delta ones, taking the read schema

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
…or and request their decode memory

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
@AarryaSaraf AarryaSaraf changed the title [Data] Iceberg DSv2 [3/14]: Size Parquet files with the decoded-size estimator and request their decode memory [Data] Iceberg DSv2 [4/15]: Size Parquet files with the decoded-size estimator and request their decode memory Nov 24, 2026
@AarryaSaraf
AarryaSaraf removed this pull request from stack #68450 November 24, 2026 01:50
@AarryaSaraf
AarryaSaraf added this pull request to stack #68499 November 24, 2026 01:51
from pyiceberg.schema import index_by_id, index_by_name, index_name_by_id

current = table_metadata.schema()
field = current.find_field(name)

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.

Time travel to a snapshot taken before a rename or drop now fails. The read projects the old snapshot's schema, so read_schema can name a column the current schema doesn't have, and current.find_field(name) raises.

I renamed col_b (and in a second run dropped it), then read the old snapshot with snapshot_id=. At #68437 V2 returns all 101 rows with col_b. Here, the ListFiles task fails with ValueError: Could not find field with name col_b. It's still there at #68449.

Suggested fix: fall back instead of failing. Return False when the name isn't in the current schema, or better, check by field ID from the read's own projection instead of by name in the current schema. Please add the rename and drop cases as tests.

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.

Update: it's not only time travel. V2 projects the pinned snapshot's schema (see #68436 (comment)), so a plain read_iceberg() right after rename_column or delete_column, before the next write, fails here the same way: ValueError: Could not find field with name col_b. I reproduced it for both rename and drop. Fixing the #68436 schema issue removes this trigger; time travel still needs the fallback here.

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.

Fixed.

if pending_tasks:
yield manifest_from_scan_tasks(tasks=pending_tasks)
tasks.append(task)
decoded_sizes = self._decoded_sizes(scan, projected_columns, tasks)

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.

list_files now keeps every planned task, reads every Parquet footer, and only then yields the first manifest. Downstream reads can't start until the whole table's footers are read. For a 100k-file table that's 100k footer reads first, and they repeat on every execution, since listing reruns each time.

The footer indexer already yields one file at a time. Could this yield each block of files as their footers arrive, with one shared actor pool, as Parquet V2 does? Please also measure time-to-first-row against [3/15] on a large table (10k–100k files). The description says it isn't measured yet.

At the top of the stack, plain Parquet files take the streaming Parquet route, but reads with a row_filter, nested columns or non-position deletes still come through here.

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.

Fixed.

or table_metadata.name_mapping() is not None
):
return None
if not all(_names_stable(table_metadata, name) for name in read_schema.names):

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.

Columns whose names aren't plain [A-Za-z0-9_] are stored in Parquet under an escaped name: PyIceberg (and Java) write payload-col as payload_x2Dcol and Payload Col as Payload_x20Col. ArrowScan finds them by field ID, but the footer reader matches by name, doesn't find them, and sizes them as all-null columns. _names_stable only compares the schema history, so it doesn't catch this.

Repro: 6 files of 2,000 rows with id and a ~2 KB string column, default read (no projection), 8 MiB budget.

  • Column named payload: estimate 24.3 MB (actual 24.3 MB), 3 read tasks requesting ~75 MB memory each.
  • Column named payload-col: estimate 195 KB (actual 24.3 MB, 124x low), all 6 files in 1 task requesting 1.2 MB.

Suggested fix: match each file's columns by the field IDs in its footer, or treat any name the writer would escape as unstable, so it falls back to the metadata size.

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.

Fixed.

table_metadata=self._table_metadata,
io=self._io,
case_sensitive=scan.case_sensitive,
read_schema=schema_to_pyarrow(projection, include_field_ids=False),

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.

Columns used only by row_filter aren't sized, but ArrowScan decodes them: it adds the filter's field IDs to the projection. With selected_fields=("id",) and row_filter=GreaterThan("payload", ...) on a ~2 KB string column, the estimate (97.5 KB) and memory request are the same as without the filter, while each task decodes ~24 MB of payload. Parquet's own path sizes filter columns for this reason. Suggested fix: include the filter's columns when sizing.

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.

Fixed.

return sizes


def _names_stable(table_metadata: "TableMetadata", name: str) -> bool:

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.

This is slow on wide tables with long schema histories. For each column read, it rebuilds index_name_by_id for the current schema, and index_name_by_id plus index_by_name for every past schema, so the cost grows with columns² × schemas. Measured on IcebergFooterSizing.create alone, before any footer is read; this runs in the ListFiles task on every execution:

  • 310 columns × 11 schemas: 2.7 s
  • 340 × 41: 12.8 s
  • 380 × 81: 30.3 s

Building each schema's indexes once, outside the per-column loop, makes it linear.

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.

Fixed.

# One unit per file: an Iceberg read unit is a whole file.
chunks.append(
FileChunk(
unit_ids=(),

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.

With unit_ids=() on every row, a data file listed twice in one plan is read once. An empty unit set is disjoint from everything, so OnlineBinPacker merges two rows for the same path in a bin into one row and keeps only the first scan task. At #68437 these rows had no chunk metadata and stayed separate.

Repro: add_files([f]), then add_files([f], check_duplicate_files=False). PyIceberg and V1 return 20 rows, and #68437's V2 take_all() returns 20. Here take_all() returns 10 while count() returns 20. It's rare, since it needs a duplicate registration, but it silently drops rows. The packer needs to keep same-path rows apart for Iceberg, since each carries its own scan task.

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.

Fixed.


if task.file.file_format != FileFormat.PARQUET:
return None
scheme, netloc, path = PyArrowFileIO.parse_location(task.file.file_path)

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.

parse_location is called without io.properties, so for scheme-less paths it ignores the FileIO's DEFAULT_SCHEME/DEFAULT_NETLOC; the reader passes them via io.new_input. With DEFAULT_SCHEME=hdfs, DEFAULT_NETLOC=nn:8020 and a table at a scheme-less location, the reader resolves ('hdfs', 'nn:8020', ...), but the sizing resolves file with the local filesystem. On HDFS the footer read would fail and take down the ListFiles task, where #68437 reads fine. I showed the two resolutions locally; there's no HDFS here to run it end to end. Passing io.properties here and at line 98 fixes it.

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.

Fixed.

# 64-bit offsets, since a packed bin's tasks can pass binary's
# 2 GiB limit.
SCAN_TASK_COLUMN_NAME: pa.array(
[cloudpickle.dumps(task) for task in tasks],

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.

Each row pickles its own FileScanTask, so a delete file shared by many data files is copied into every row. Partition-scoped position deletes (Spark merge-on-read before Iceberg 1.6, Flink upserts) apply to every data file in the partition, so the manifest grows as data files × delete files.

Measured: 200 data files sharing 100 delete files (20-column stats) give 11.7 MB of manifest, vs 0.18 MB for V1, which pickles a whole read task at once (66x). That's about 580 B per pair, so 10k files × 500 deletes is ~2.9 GB in the listing task. #68447 [13/15] strips stats, which shrinks each copy but keeps the copies. Storing each delete file once per manifest block and referencing it by index would fix it.

(This line predates this PR; this is the first place in the stack that changes the manifest code.)

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.

went with compression for simplicity purposes

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants