Skip to content

Commit 13fe7d6

Browse files
committed
move _manifests to manifest.py
1 parent 7d82252 commit 13fe7d6

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

pyiceberg/manifest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
List,
2929
Literal,
3030
Optional,
31+
Tuple,
3132
Type,
3233
)
3334

35+
from cachetools import LRUCache, cached
36+
from cachetools.keys import hashkey
3437
from pydantic_core import to_json
3538

3639
from pyiceberg.avro.file import AvroFile, AvroOutputFile
@@ -620,6 +623,13 @@ def fetch_manifest_entry(self, io: FileIO, discard_deleted: bool = True) -> List
620623
]
621624

622625

626+
@cached(cache=LRUCache(maxsize=128), key=lambda io, manifest_list: hashkey(manifest_list))
627+
def _manifests(io: FileIO, manifest_list: str) -> Tuple[ManifestFile, ...]:
628+
"""Read and cache manifests from the given manifest list, returning a tuple to prevent modification."""
629+
file = io.new_input(manifest_list)
630+
return tuple(read_manifest_list(file))
631+
632+
623633
def read_manifest_list(input_file: InputFile) -> Iterator[ManifestFile]:
624634
"""
625635
Read the manifests from the manifest list.

pyiceberg/table/snapshots.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
import time
2020
from collections import defaultdict
2121
from enum import Enum
22-
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, Iterable, List, Mapping, Optional, Tuple
22+
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, Iterable, List, Mapping, Optional
2323

24-
from cachetools import LRUCache, cached
25-
from cachetools.keys import hashkey
2624
from pydantic import Field, PrivateAttr, model_serializer
2725

2826
from pyiceberg.io import FileIO
29-
from pyiceberg.manifest import DataFile, DataFileContent, ManifestFile, read_manifest_list
27+
from pyiceberg.manifest import DataFile, DataFileContent, ManifestFile, _manifests
3028
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec
3129
from pyiceberg.schema import Schema
3230

@@ -232,13 +230,6 @@ def __eq__(self, other: Any) -> bool:
232230
)
233231

234232

235-
@cached(cache=LRUCache(maxsize=128), key=lambda io, manifest_list: hashkey(manifest_list))
236-
def _manifests(io: FileIO, manifest_list: str) -> Tuple[ManifestFile, ...]:
237-
"""Read and cache manifests from the given manifest list, returning a tuple to prevent modification."""
238-
file = io.new_input(manifest_list)
239-
return tuple(read_manifest_list(file))
240-
241-
242233
class Snapshot(IcebergBaseModel):
243234
snapshot_id: int = Field(alias="snapshot-id")
244235
parent_snapshot_id: Optional[int] = Field(alias="parent-snapshot-id", default=None)

tests/utils/test_manifest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
ManifestEntryStatus,
3333
ManifestFile,
3434
PartitionFieldSummary,
35+
_manifests,
3536
read_manifest_list,
3637
write_manifest,
3738
write_manifest_list,
3839
)
3940
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionField, PartitionSpec
4041
from pyiceberg.schema import Schema
41-
from pyiceberg.table.snapshots import Operation, Snapshot, Summary, _manifests
42+
from pyiceberg.table.snapshots import Operation, Snapshot, Summary
4243
from pyiceberg.transforms import IdentityTransform
4344
from pyiceberg.typedef import Record, TableVersion
4445
from pyiceberg.types import IntegerType, NestedField
@@ -314,8 +315,7 @@ def test_read_manifest_v2(generated_manifest_file_file_v2: str) -> None:
314315

315316

316317
def test_read_manifest_cache(generated_manifest_file_file_v2: str) -> None:
317-
# Mock the read_manifest_list function relative to the module path
318-
with patch("pyiceberg.table.snapshots.read_manifest_list") as mocked_read_manifest_list:
318+
with patch("pyiceberg.manifest.read_manifest_list") as mocked_read_manifest_list:
319319
io = load_file_io()
320320

321321
snapshot = Snapshot(

0 commit comments

Comments
 (0)