Skip to content

Commit d705c76

Browse files
committed
1. support returning rewrite results
2. write tests for rewrite manifests
1 parent 76740df commit d705c76

File tree

3 files changed

+162
-296
lines changed

3 files changed

+162
-296
lines changed

pyiceberg/table/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
update_table_metadata,
113113
)
114114
from pyiceberg.table.update.schema import UpdateSchema
115-
from pyiceberg.table.update.snapshot import ManageSnapshots, UpdateSnapshot, _FastAppendFiles
115+
from pyiceberg.table.update.snapshot import ManageSnapshots, RewriteManifestsResult, UpdateSnapshot, _FastAppendFiles
116116
from pyiceberg.table.update.spec import UpdateSpec
117117
from pyiceberg.table.update.statistics import UpdateStatistics
118118
from pyiceberg.transforms import IdentityTransform
@@ -420,9 +420,12 @@ def update_snapshot(self, snapshot_properties: Dict[str, str] = EMPTY_DICT) -> U
420420
"""
421421
return UpdateSnapshot(self, io=self._table.io, snapshot_properties=snapshot_properties)
422422

423-
def rewrite_manifests(self, spec_id: Optional[int] = None) -> None:
423+
def rewrite_manifests(self, spec_id: Optional[int] = None) -> RewriteManifestsResult:
424+
if self._table.current_snapshot() is None:
425+
return RewriteManifestsResult(rewritten_manifests=[], added_manifests=[])
424426
with self.update_snapshot().rewrite() as rewrite:
425-
rewrite.rewrite_manifests()
427+
rewritten = rewrite.rewrite_manifests()
428+
return rewritten
426429

427430
def append(self, df: pa.Table, snapshot_properties: Dict[str, str] = EMPTY_DICT) -> None:
428431
"""
@@ -1174,7 +1177,7 @@ def add_files(
11741177
def rewrite_manifests(
11751178
self,
11761179
spec_id: Optional[int] = None,
1177-
) -> None:
1180+
) -> RewriteManifestsResult:
11781181
"""
11791182
Shorthand API for Rewriting manifests for the table.
11801183
@@ -1183,7 +1186,7 @@ def rewrite_manifests(
11831186
11841187
"""
11851188
with self.transaction() as tx:
1186-
tx.rewrite_manifests(spec_id=spec_id)
1189+
return tx.rewrite_manifests(spec_id=spec_id)
11871190

11881191
def update_spec(self, case_sensitive: bool = True) -> UpdateSpec:
11891192
return UpdateSpec(Transaction(self, autocommit=True), case_sensitive=case_sensitive)

0 commit comments

Comments
 (0)