Skip to content

Commit cb9414f

Browse files
committed
WIP
1 parent f116bab commit cb9414f

4 files changed

Lines changed: 38 additions & 7 deletions

File tree

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyiceberg/catalog/rest/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class IdentifierKind(Enum):
138138
SIGV4_REGION = "rest.signing-region"
139139
SIGV4_SERVICE = "rest.signing-name"
140140
OAUTH2_SERVER_URI = "oauth2-server-uri"
141+
SNAPSHOT_LOADING_MODE = "snapshot-loading-mode"
141142

142143
NAMESPACE_SEPARATOR = b"\x1f".decode(UTF8)
143144

@@ -678,7 +679,15 @@ def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
678679

679680
@retry(**_RETRY_ARGS)
680681
def load_table(self, identifier: Union[str, Identifier]) -> Table:
681-
response = self._session.get(self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier)))
682+
683+
params = {}
684+
if mode := self.properties.get(SNAPSHOT_LOADING_MODE):
685+
if mode in {'all', 'refs'}:
686+
params['snapshots'] = mode
687+
else:
688+
raise ValueError("Invalid snapshot-loading-mode: {}")
689+
690+
response = self._session.get(self.url(Endpoints.load_table, prefixed=True, **self._split_identifier_for_path(identifier)), params=params)
682691
try:
683692
response.raise_for_status()
684693
except HTTPError as exc:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ psycopg2-binary = { version = ">=2.9.6", optional = true }
8080
sqlalchemy = { version = "^2.0.18", optional = true }
8181
getdaft = { version = ">=0.2.12", optional = true }
8282
cachetools = "^5.5.0"
83-
pyiceberg-core = { file = "/Users/fokko.driesprong/work/iceberg-rust/bindings/python/dist/pyiceberg_core-0.22123123.0-cp39-abi3-macosx_11_0_arm64.whl" }
83+
pyiceberg-core = { file = "/Users/fokko.driesprong/work/iceberg-rust/bindings/python/dist/pyiceberg_core-0.12315135178.0-cp39-abi3-macosx_11_0_arm64.whl" }
8484
polars = { version = "^1.21.0", optional = true }
8585
thrift-sasl = { version = ">=0.4.3", optional = true }
8686
kerberos = {version = "^1.3.1", optional = true}

tests/catalog/test_rest.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import pyiceberg
2626
from pyiceberg.catalog import PropertiesUpdateSummary, load_catalog
27-
from pyiceberg.catalog.rest import OAUTH2_SERVER_URI, RestCatalog
27+
from pyiceberg.catalog.rest import OAUTH2_SERVER_URI, RestCatalog, SNAPSHOT_LOADING_MODE
2828
from pyiceberg.exceptions import (
2929
AuthorizationExpiredError,
3030
NamespaceAlreadyExistsError,
@@ -852,6 +852,28 @@ def test_load_table_200(rest_mock: Mocker, example_table_metadata_with_snapshot_
852852
assert actual.metadata.model_dump() == expected.metadata.model_dump()
853853
assert actual == expected
854854

855+
def test_load_table_200_loading_mode(rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: Dict[str, Any]) -> None:
856+
rest_mock.get(
857+
f"{TEST_URI}v1/namespaces/fokko/tables/table?snapshots=refs",
858+
json=example_table_metadata_with_snapshot_v1_rest_json,
859+
status_code=200,
860+
request_headers=TEST_HEADERS,
861+
)
862+
catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN, **{
863+
SNAPSHOT_LOADING_MODE: 'refs'
864+
})
865+
actual = catalog.load_table(("fokko", "table"))
866+
expected = Table(
867+
identifier=("fokko", "table"),
868+
metadata_location=example_table_metadata_with_snapshot_v1_rest_json["metadata-location"],
869+
metadata=TableMetadataV1(**example_table_metadata_with_snapshot_v1_rest_json["metadata"]),
870+
io=load_file_io(),
871+
catalog=catalog,
872+
)
873+
# First compare the dicts
874+
assert actual.metadata.model_dump() == expected.metadata.model_dump()
875+
assert actual == expected
876+
855877

856878
def test_load_table_honor_access_delegation(
857879
rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: Dict[str, Any]

0 commit comments

Comments
 (0)