Skip to content

Commit ceb612c

Browse files
committed
fixup! REST: Add support for page-size in list_views
1 parent 7cf58d3 commit ceb612c

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

pyiceberg/catalog/rest/__init__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,11 +1044,17 @@ def list_tables(self, namespace: str | Identifier) -> list[Identifier]:
10441044
namespace_concat = self._encode_namespace_path(namespace_tuple)
10451045
url = self.url(Endpoints.list_tables, namespace=namespace_concat)
10461046

1047+
params: dict[str, str] = {}
1048+
page_size = property_as_int(self.properties, PAGE_SIZE, None)
1049+
if page_size is not None:
1050+
if page_size <= 0:
1051+
raise ValueError(f"{PAGE_SIZE} must be a positive integer")
1052+
params["pageSize"] = str(page_size)
1053+
10471054
tables: list[Identifier] = []
10481055
page_token: str | None = None
10491056

10501057
while True:
1051-
params: dict[str, str] = {}
10521058
if page_token:
10531059
params["pageToken"] = page_token
10541060
response = self._session.get(url, params=params)
@@ -1151,7 +1157,8 @@ def list_views(self, namespace: str | Identifier) -> list[Identifier]:
11511157
namespace_tuple = self._check_valid_namespace_identifier(namespace)
11521158
namespace_concat = self._encode_namespace_path(namespace_tuple)
11531159
url = self.url(Endpoints.list_views, namespace=namespace_concat)
1154-
params = {}
1160+
1161+
params: dict[str, str] = {}
11551162
page_size = property_as_int(self.properties, PAGE_SIZE, None)
11561163
if page_size is not None:
11571164
if page_size <= 0:
@@ -1273,11 +1280,17 @@ def list_namespaces(self, namespace: str | Identifier = ()) -> list[Identifier]:
12731280
self._check_endpoint(Capability.V1_LIST_NAMESPACES)
12741281
namespace_tuple = self.identifier_to_tuple(namespace)
12751282

1283+
params: dict[str, str] = {}
1284+
page_size = property_as_int(self.properties, PAGE_SIZE, None)
1285+
if page_size is not None:
1286+
if page_size <= 0:
1287+
raise ValueError(f"{PAGE_SIZE} must be a positive integer")
1288+
params["pageSize"] = str(page_size)
1289+
12761290
namespaces: list[Identifier] = []
12771291
page_token: str | None = None
12781292

12791293
while True:
1280-
params: dict[str, str] = {}
12811294
if namespace_tuple:
12821295
params["parent"] = self._encode_namespace_path(namespace_tuple)
12831296
if page_token:

tests/catalog/test_rest.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,29 @@ def test_list_tables_paginated_200_none_next_page_token(rest_mock: Mocker) -> No
565565
]
566566

567567

568+
def test_list_tables_page_size(rest_mock: Mocker) -> None:
569+
namespace = "examples"
570+
rest_mock.get(
571+
f"{TEST_URI}v1/namespaces/{namespace}/tables",
572+
json={
573+
"identifiers": [
574+
{"namespace": ["examples"], "name": "table1"},
575+
{"namespace": ["examples"], "name": "table2"},
576+
],
577+
},
578+
status_code=200,
579+
request_headers=TEST_HEADERS,
580+
)
581+
582+
result = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN, **{PAGE_SIZE: "100"}).list_tables(namespace)
583+
assert rest_mock.last_request.url == f"{TEST_URI}v1/namespaces/examples/tables?pageSize=100"
584+
585+
assert result == [
586+
("examples", "table1"),
587+
("examples", "table2"),
588+
]
589+
590+
568591
def test_list_tables_200_sigv4(rest_mock: Mocker) -> None:
569592
namespace = "examples"
570593
rest_mock.get(
@@ -1049,6 +1072,25 @@ def test_list_namespaces_paginated_200_none_next_page_token(rest_mock: Mocker) -
10491072
]
10501073

10511074

1075+
def test_list_namespaces_page_size(rest_mock: Mocker) -> None:
1076+
rest_mock.get(
1077+
f"{TEST_URI}v1/namespaces",
1078+
json={
1079+
"namespaces": [["ns1"], ["ns2"]],
1080+
},
1081+
status_code=200,
1082+
request_headers=TEST_HEADERS,
1083+
)
1084+
1085+
result = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN, **{PAGE_SIZE: "100"}).list_namespaces()
1086+
assert rest_mock.last_request.url == f"{TEST_URI}v1/namespaces?pageSize=100"
1087+
1088+
assert result == [
1089+
("ns1",),
1090+
("ns2",),
1091+
]
1092+
1093+
10521094
def test_list_namespace_with_parent_404(rest_mock: Mocker) -> None:
10531095
rest_mock.get(
10541096
f"{TEST_URI}v1/namespaces?parent=some_namespace",

0 commit comments

Comments
 (0)