Skip to content

Commit 739373f

Browse files
authored
REST: Rename rest-scan-planning-enabled to scan-planning-mode (#3376)
# Rationale for this change Boolean properties should be avoided as much as possible. We may consider introducing a new scan planning mode in the future. The Java implementation has already changed from `rest-scan-planning-enabled` to `scan-planning-mode` in apache/iceberg#15572. ## Are these changes tested? Yes. ## Are there any user-facing changes? Rename `rest-scan-planning-enabled` to `scan-planning-mode`. <!-- In the case of user-facing changes, please add the changelog label. -->
1 parent 706390f commit 739373f

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

pyiceberg/catalog/rest/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ class IdentifierKind(Enum):
225225
VIEW = "view"
226226

227227

228+
class ScanPlanningMode(Enum):
229+
CLIENT = "client"
230+
SERVER = "server"
231+
232+
228233
ACCESS_DELEGATION_DEFAULT = "vended-credentials"
229234
AUTHORIZATION_HEADER = "Authorization"
230235
BEARER_PREFIX = "Bearer"
@@ -255,8 +260,8 @@ class IdentifierKind(Enum):
255260
SNAPSHOT_LOADING_MODE = "snapshot-loading-mode"
256261
AUTH = "auth"
257262
CUSTOM = "custom"
258-
REST_SCAN_PLANNING_ENABLED = "rest-scan-planning-enabled"
259-
REST_SCAN_PLANNING_ENABLED_DEFAULT = False
263+
SCAN_PLANNING_MODE = "scan-planning-mode"
264+
SCAN_PLANNING_MODE_DEFAULT = ScanPlanningMode.CLIENT.value
260265
# for backwards compatibility with older REST servers where it can be assumed that a particular
261266
# server supports view endpoints but doesn't send the "endpoints" field in the ConfigResponse
262267
VIEW_ENDPOINTS_SUPPORTED = "view-endpoints-supported"
@@ -480,9 +485,8 @@ def _load_file_io(self, properties: Properties = EMPTY_DICT, location: str | Non
480485
@override
481486
def supports_server_side_planning(self) -> bool:
482487
"""Check if the catalog supports server-side scan planning."""
483-
return Capability.V1_SUBMIT_TABLE_SCAN_PLAN in self._supported_endpoints and property_as_bool(
484-
self.properties, REST_SCAN_PLANNING_ENABLED, REST_SCAN_PLANNING_ENABLED_DEFAULT
485-
)
488+
scan_planning_mode = ScanPlanningMode(self.properties.get(SCAN_PLANNING_MODE, SCAN_PLANNING_MODE_DEFAULT))
489+
return Capability.V1_SUBMIT_TABLE_SCAN_PLAN in self._supported_endpoints and scan_planning_mode == ScanPlanningMode.SERVER
486490

487491
@retry(**_RETRY_ARGS)
488492
def _plan_table_scan(self, identifier: str | Identifier, request: PlanTableScanRequest) -> PlanningResponse:

tests/catalog/test_rest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
Endpoint,
4343
HttpMethod,
4444
RestCatalog,
45+
ScanPlanningMode,
4546
)
4647
from pyiceberg.exceptions import (
4748
AuthorizationExpiredError,
@@ -2546,7 +2547,7 @@ def test_server_side_planning_enabled_by_property(self, rest_mock: Mocker) -> No
25462547
"rest",
25472548
uri=TEST_URI,
25482549
token=TEST_TOKEN,
2549-
**{"rest-scan-planning-enabled": "true"},
2550+
**{"scan-planning-mode": ScanPlanningMode.SERVER.value},
25502551
)
25512552

25522553
assert catalog.supports_server_side_planning() is True
@@ -2562,7 +2563,7 @@ def test_server_side_planning_disabled_when_endpoint_unsupported(self, requests_
25622563
"rest",
25632564
uri=TEST_URI,
25642565
token=TEST_TOKEN,
2565-
**{"rest-scan-planning-enabled": "true"},
2566+
**{"scan-planning-mode": ScanPlanningMode.SERVER.value},
25662567
)
25672568

25682569
assert catalog.supports_server_side_planning() is False
@@ -2572,7 +2573,7 @@ def test_server_side_planning_explicitly_disabled(self, rest_mock: Mocker) -> No
25722573
"rest",
25732574
uri=TEST_URI,
25742575
token=TEST_TOKEN,
2575-
**{"rest-scan-planning-enabled": "false"},
2576+
**{"scan-planning-mode": ScanPlanningMode.CLIENT.value},
25762577
)
25772578

25782579
assert catalog.supports_server_side_planning() is False
@@ -2581,7 +2582,7 @@ def test_server_side_planning_enabled_from_server_config(self, rest_mock: Mocker
25812582
rest_mock.get(
25822583
f"{TEST_URI}v1/config",
25832584
json={
2584-
"defaults": {"rest-scan-planning-enabled": "true"},
2585+
"defaults": {"scan-planning-mode": "server"},
25852586
"overrides": {},
25862587
"endpoints": ["POST /v1/{prefix}/namespaces/{namespace}/tables/{table}/plan"],
25872588
},

0 commit comments

Comments
 (0)