Skip to content

Commit b394c5c

Browse files
committed
fix: return empty file metadata tables for snapshots without manifests
1 parent 0a2c3d2 commit b394c5c

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎pyiceberg/table/inspect.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,8 @@ def _files(self, snapshot_id: int | None = None, data_file_filter: set[DataFileC
887887
snapshot.manifests(io, self.tbl.encryption_manager),
888888
)
889889
)
890+
if not results:
891+
return self._get_files_schema().empty_table()
890892
return pa.concat_tables(results)
891893

892894
def files(self, snapshot_id: int | None = None) -> pa.Table:
@@ -967,15 +969,13 @@ def _all_files(self, data_file_filter: set[DataFileContent] | None = None) -> pa
967969
"""
968970
import pyarrow as pa
969971

970-
snapshots = self.tbl.snapshots()
971-
if not snapshots:
972-
return pa.Table.from_pylist([], schema=self._get_files_schema())
973-
974972
executor = ExecutorFactory.get_or_create()
975973
encryption_manager = self.tbl.encryption_manager
976-
manifest_lists = executor.map(lambda snapshot: snapshot.manifests(self.tbl.io, encryption_manager), snapshots)
974+
manifest_lists = executor.map(lambda snapshot: snapshot.manifests(self.tbl.io, encryption_manager), self.tbl.snapshots())
977975

978976
unique_manifests = {(manifest.manifest_path, manifest) for manifest_list in manifest_lists for manifest in manifest_list}
977+
if not unique_manifests:
978+
return self._get_files_schema().empty_table()
979979

980980
file_lists = executor.map(
981981
lambda args: self._get_files_from_manifest(*args), [(manifest, data_file_filter) for _, manifest in unique_manifests]

‎tests/table/test_inspect.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ def test_inspect_entries_and_files_render_null_bound(catalog: InMemoryCatalog) -
7676
assert files_metrics["upper_bound"] is None
7777

7878

79+
@pytest.mark.parametrize("method", ["files", "data_files", "delete_files", "all_files", "all_data_files", "all_delete_files"])
80+
def test_inspect_files_of_snapshot_without_manifests(catalog: InMemoryCatalog, method: str) -> None:
81+
tbl = catalog.create_table("default.no_manifests", Schema(NestedField(1, "x", LongType(), required=False)))
82+
tbl.append(pa.table({"x": pa.array([], pa.int64())}))
83+
84+
assert getattr(tbl.inspect, method)() == tbl.inspect._get_files_schema().empty_table()
85+
86+
7987
@pytest.mark.parametrize("newest_first", [False, True])
8088
def test_partitions_last_updated_uses_latest_snapshot_regardless_of_order(newest_first: bool) -> None:
8189
# Manifest entries are visited in manifest order, which is not chronological, so the

0 commit comments

Comments
 (0)