Repository navigation
[Data] Iceberg DSv2 [1/15]: Let the table's REST catalog plan the scan when server-side planning is on - #68498
AarryaSaraf wants to merge 1 commit into
Conversation
…e listing task when server-side planning is on Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
|
|
||
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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| 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, | ||
| ) |
There was a problem hiding this comment.
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)
Summary
When a table's REST catalog plans scans on its server, V1
read_icebergasks 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'sDataScan, 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 movingread_icebergonto 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: truein PyIceberg 0.11,scan-planning-mode: serverin 0.12. Thentable.scan().plan_files(), V1's route, sends onePOST /v1/namespaces/{ns}/tables/{table}/planwith the snapshot and filter, and reads files from the server's answer.V2's
IcebergFileIndexerruns in theListFilestask and buildsDataScan(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
ServerSidePlanning. Files:_internal/datasource_v2/formats/iceberg/iceberg_file_indexer.py.ServerSidePlanning.for_table(table)returnsNoneunless the table's catalog is aRestCatalogwhosesupports_server_side_planning()is true. Older PyIceberg releases have no such method and getNone.table.io, which the listing task gets today, so the task receives no credential it didn't have. They are left out ofrepr.IcebergFileIndexer(server_side_planning=...)rebuilds the catalog in the listing task (oneGET /v1/config) and passescatalog=andtable_identifier=toDataScan, soplan_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.tests/datasource/test_iceberg.py.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.for_tableisNonefor 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 addedSubsystems
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()readsscan-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