Skip to content

Commit 0278cdd

Browse files
committed
Use version-hint.text for StaticTable when metadata_location does not ends with '.metadata.json'
1 parent 8adf246 commit 0278cdd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pyiceberg/table/__init__.py

+20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717
from __future__ import annotations
1818

19+
import os
1920
import itertools
2021
import uuid
2122
import warnings
@@ -1378,8 +1379,27 @@ def refresh(self) -> Table:
13781379
"""Refresh the current table metadata."""
13791380
raise NotImplementedError("To be implemented")
13801381

1382+
@classmethod
1383+
def _metadata_location_from_version_hint(cls, metadata_location: str, properties: Properties = EMPTY_DICT) -> str:
1384+
version_hint_location = os.path.join(metadata_location, 'metadata', 'version-hint.text')
1385+
io = load_file_io(properties=properties, location=version_hint_location)
1386+
file = io.new_input(version_hint_location)
1387+
1388+
with file.open() as stream:
1389+
content = file.open().read().decode("utf-8")
1390+
1391+
if content.endswith('.metadata.json'):
1392+
return os.path.join(metadata_location, 'metadata', content)
1393+
elif content.isnumeric():
1394+
return os.path.join(metadata_location, 'metadata', 'v%s.metadata.json'.format(content))
1395+
else:
1396+
return os.path.join(metadata_location, 'metadata', '%s.metadata.json'.format(content))
1397+
13811398
@classmethod
13821399
def from_metadata(cls, metadata_location: str, properties: Properties = EMPTY_DICT) -> StaticTable:
1400+
if not metadata_location.endswith('.metadata.json'):
1401+
metadata_location = StaticTable._metadata_location_from_version_hint(metadata_location, properties)
1402+
13831403
io = load_file_io(properties=properties, location=metadata_location)
13841404
file = io.new_input(metadata_location)
13851405

0 commit comments

Comments
 (0)