|
17 | 17 | from __future__ import annotations |
18 | 18 |
|
19 | 19 | import itertools |
| 20 | +import os |
20 | 21 | import uuid |
21 | 22 | import warnings |
22 | 23 | from abc import ABC, abstractmethod |
@@ -1378,8 +1379,27 @@ def refresh(self) -> Table: |
1378 | 1379 | """Refresh the current table metadata.""" |
1379 | 1380 | raise NotImplementedError("To be implemented") |
1380 | 1381 |
|
| 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 = stream.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 | + |
1381 | 1398 | @classmethod |
1382 | 1399 | 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 | + |
1383 | 1403 | io = load_file_io(properties=properties, location=metadata_location) |
1384 | 1404 | file = io.new_input(metadata_location) |
1385 | 1405 |
|
|
0 commit comments