Skip to content

[Data] Iceberg DSv2 [1/15]: Let the table's REST catalog plan the scan when server-side planning is on - #68498

Open
AarryaSaraf wants to merge 1 commit into
masterfrom
iceberg-dsv2-rest-planning
Open

AarryaSaraf wants to merge 1 commit into
masterfrom
iceberg-dsv2-rest-planning

Conversation

@AarryaSaraf

Copy link
Copy Markdown
Contributor

Summary

When a table's REST catalog plans scans on its server, V1 read_iceberg asks the server for the file list, but V2's listing step plans by itself and ignores the setting (raised on #68152's review). This PR has the V2 listing task rebuild the catalog from the properties the driver resolved and give it to PyIceberg's DataScan, so PyIceberg sends the server's plan request, as it does for V1. Planning stays in the listing task, not on the driver. 1 of 15 in the stack moving read_iceberg onto Datasource V2 (#66181).

Before

A REST catalog plans on its server when the server offers the plan endpoint and the client turns it on: rest-scan-planning-enabled: true in PyIceberg 0.11, scan-planning-mode: server in 0.12. Then table.scan().plan_files(), V1's route, sends one POST /v1/namespaces/{ns}/tables/{table}/plan with the snapshot and filter, and reads files from the server's answer.

V2's IcebergFileIndexer runs in the ListFiles task and builds DataScan(table_metadata, io, ...) without a catalog, so it always reads the manifest list and manifests itself. With an honest server both give the same files. They differ when the server's plan differs from the table metadata, e.g. a catalog that leaves out files the user may not read.

After

  1. ServerSidePlanning. Files: _internal/datasource_v2/formats/iceberg/iceberg_file_indexer.py.
    • ServerSidePlanning.for_table(table) returns None unless the table's catalog is a RestCatalog whose supports_server_side_planning() is true. Older PyIceberg releases have no such method and get None.
    • It holds the catalog's class, name and resolved properties, plus the table identifier. PyIceberg already merges those properties into table.io, which the listing task gets today, so the task receives no credential it didn't have. They are left out of repr.
  2. The indexer plans through the catalog when given one. Same file. IcebergFileIndexer(server_side_planning=...) rebuilds the catalog in the listing task (one GET /v1/config) and passes catalog= and table_identifier= to DataScan, so plan_files() asks the server. Unset, which is the default, keeps today's local planning. Nothing passes it yet; [2/15] wires it from the datasource.
  3. Tests. Files: tests/datasource/test_iceberg.py.
    • A fake REST catalog fixture (stdlib ThreadingHTTPServer) serves the fixture table, offers server planning, records requests, and plans one of the table's files, so the listed files show whose plan was used.
    • Listing, after a pickle round trip like the one to the listing task, lists exactly the server's file, with one plan request carrying the driver's snapshot and filter.
    • for_table is None for a REST catalog with planning off and for a SQL catalog.
flowchart TD
    subgraph Before
        subgraph BS["Subsystem: IO (formats/iceberg/)"]
            subgraph BC["ListFiles task: IcebergFileIndexer._plan_files"]
                B1["DataScan(table_metadata, io)<br/>no catalog"] -->|"reads manifest list + manifests"| B2["FileScanTasks"]
            end
        end
    end
    subgraph After
        subgraph AS["Subsystem: IO (formats/iceberg/)"]
            subgraph AC["ListFiles task: IcebergFileIndexer._plan_files"]
                A0{"server_side_planning set?"}
                A0 -->|"no (default)"| A1["DataScan(table_metadata, io)"]
                A1 -->|"reads manifest list + manifests"| A3["FileScanTasks"]
                A0 -->|yes| A2["ServerSidePlanning.load_catalog()<br/>DataScan(..., catalog, table_identifier)"]
                A2 -->|"POST .../plan with snapshot + filter"| A3
            end
        end
    end
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    class A0,A2 added
Loading

Subsystems

IO (formats/iceberg/iceberg_file_indexer.py).

Testing

pytest python/ray/data/tests/datasource/test_iceberg.py: 100 passed at this PR's head (pyarrow 24.0.0, PyIceberg 0.11.1). 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. CI runs PyIceberg 0.12.0 on Python 3.14; I checked that path against 0.12.0rc1's source only: supports_server_side_planning() reads scan-planning-mode, which the tests also set.

Not a duplicate: no open PR adds REST server-side planning to Ray's Iceberg reader. I searched open PRs with "iceberg" in the title and for "server-side planning iceberg" on 2026-11-23; the only Iceberg PRs are this stack and #68252, which 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

…e listing task when server-side planning is on

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Aarrya <[email protected]>
@AarryaSaraf
AarryaSaraf added this pull request to stack #68499 November 24, 2026 01:51
@abhishekverma-ray abhishekverma-ray self-assigned this Nov 24, 2026
@abhishekverma-ray abhishekverma-ray added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Nov 24, 2026

def load_catalog(self) -> "RestCatalog":
"""Rebuild the driver's catalog, which fetches the server's config again."""
return self.catalog_class(self.catalog_name, **self.catalog_properties)

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.

Small note: this makes the listing task, which runs on a worker, talk to the catalog server: GET /v1/config, and with credential a fresh OAuth token from the token endpoint. Before, only the driver talked to the catalog (the module docstring says its config may exist only on the driver). So with server-side planning on, a cluster whose workers can't reach the catalog or its OAuth server now fails at listing, and settings like an ssl CA-bundle path or SigV4 credentials must also work on the worker. Probably fine on most clusters, but worth a line in the read_iceberg docs and a clear error when the rebuild fails.

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.

Agreed. I'd rather keep planning off the driver, so I added this to the read_iceberg docs, and the listing task now raises a clear error when it can't load the catalog.

# with a catalog that plans on its server asks it for the file list.
planning_kwargs: Dict[str, Any] = {}
if self._server_side_planning is not None:
planning_kwargs = {

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.

Edge case, from reading the code (I didn't run it): when the table has no snapshot at read_iceberg() time, the pinned snapshot_id is None. Local planning then uses the driver's metadata and lists nothing. With server-side planning, the plan request goes out without a snapshot-id, so the server plans whatever snapshot is current when the listing task runs. Data written after read_iceberg() can then show up, and two runs of the same Dataset can differ, which breaks [2/15]'s promise that every task reads the same snapshot. Simple fix: when there's no snapshot, list no files instead of planning.

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.

@AarryaSaraf
AarryaSaraf marked this pull request as ready for review November 24, 2026 20:59
@AarryaSaraf
AarryaSaraf requested review from a team as code owners November 24, 2026 20:59

@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 server-side scan planning in the Iceberg file indexer when using a REST catalog, allowing the listing task to rebuild the catalog and delegate planning to the server. Comprehensive unit tests with a mock REST catalog are also added. The review feedback suggests defensive programming improvements, specifically using getattr to safely access the table's catalog attribute and consolidating DataScan arguments into a single dictionary to prevent potential duplicate keyword argument errors.

Comment on lines +98 to +108
catalog = table.catalog
# Older PyIceberg releases can't plan on the server.
supports_server_side_planning = getattr(
catalog, "supports_server_side_planning", None
)
if (
not isinstance(catalog, RestCatalog)
or supports_server_side_planning is None
or not supports_server_side_planning()
):
return None

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 enforce defensive programming and handle potentially missing or null attributes on the table object (e.g., if a custom table or StaticTable is used), it is safer to use getattr(table, "catalog", None) and check if the catalog is a RestCatalog first. This avoids potential AttributeErrors and makes the logic cleaner.

        catalog = getattr(table, "catalog", None)
        if not isinstance(catalog, RestCatalog):
            return None

        # Older PyIceberg releases can't plan on the server.
        supports_server_side_planning = getattr(
            catalog, "supports_server_side_planning", None
        )
        if (
            supports_server_side_planning is None
            or not supports_server_side_planning()
        ):
            return None

Comment on lines +196 to 209
planning_kwargs: Dict[str, Any] = {}
if self._server_side_planning is not None:
planning_kwargs = {
"catalog": self._server_side_planning.load_catalog(),
"table_identifier": self._server_side_planning.table_identifier,
}
scan = DataScan(
table_metadata=self._table_metadata,
io=self._io,
row_filter=self._row_filter,
snapshot_id=self._snapshot_id,
**planning_kwargs,
**self._scan_kwargs,
)

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 prevent potential TypeErrors due to duplicate keyword arguments (e.g., if self._scan_kwargs already contains catalog or table_identifier), we can construct a single dictionary of arguments and update/override them. This is more robust and pythonic.

        scan_kwargs = {
            "table_metadata": self._table_metadata,
            "io": self._io,
            "row_filter": self._row_filter,
            "snapshot_id": self._snapshot_id,
            **self._scan_kwargs,
        }
        if self._server_side_planning is not None:
            scan_kwargs["catalog"] = self._server_side_planning.load_catalog()
            scan_kwargs["table_identifier"] = self._server_side_planning.table_identifier

        scan = DataScan(**scan_kwargs)

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

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