Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pyiceberg/table/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ def _files(self, snapshot_id: int | None = None, data_file_filter: set[DataFileC
snapshot.manifests(io, self.tbl.encryption_manager),
)
)
if not results:
return self._get_files_schema().empty_table()
return pa.concat_tables(results)

def files(self, snapshot_id: int | None = None) -> pa.Table:
Expand Down Expand Up @@ -986,15 +988,13 @@ def _all_files(self, data_file_filter: set[DataFileContent] | None = None) -> pa
"""
import pyarrow as pa

snapshots = self.tbl.snapshots()
if not snapshots:
return pa.Table.from_pylist([], schema=self._get_files_schema())

executor = ExecutorFactory.get_or_create()
encryption_manager = self.tbl.encryption_manager
manifest_lists = executor.map(lambda snapshot: snapshot.manifests(self.tbl.io, encryption_manager), snapshots)
manifest_lists = executor.map(lambda snapshot: snapshot.manifests(self.tbl.io, encryption_manager), self.tbl.snapshots())

unique_manifests = {(manifest.manifest_path, manifest) for manifest_list in manifest_lists for manifest in manifest_list}
if not unique_manifests:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since we now return early when there are no manifests rather than no snapshots, could we update the Returns: section of the docstring to match? It still says "or an empty table if the table has no snapshots".

return self._get_files_schema().empty_table()

file_lists = executor.map(
lambda args: self._get_files_from_manifest(*args), [(manifest, data_file_filter) for _, manifest in unique_manifests]
Expand Down
17 changes: 17 additions & 0 deletions tests/table/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMem
assert files[0]["column_sizes"] is None


@pytest.mark.parametrize("method", ["files", "data_files", "delete_files", "all_files", "all_data_files", "all_delete_files"])
def test_inspect_files_of_snapshot_without_manifests(catalog: InMemoryCatalog, method: str) -> None:
tbl = catalog.create_table("default.no_manifests", Schema(NestedField(1, "x", LongType(), required=False)))
tbl.append(pa.table({"x": pa.array([], pa.int64())}))

assert getattr(tbl.inspect, method)() == tbl.inspect._get_files_schema().empty_table()
Comment on lines +107 to +112

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (non-blocking): These are six simple cases on the same table, so a loop avoids creating the table six times:

Suggested change
@pytest.mark.parametrize("method", ["files", "data_files", "delete_files", "all_files", "all_data_files", "all_delete_files"])
def test_inspect_files_of_snapshot_without_manifests(catalog: InMemoryCatalog, method: str) -> None:
tbl = catalog.create_table("default.no_manifests", Schema(NestedField(1, "x", LongType(), required=False)))
tbl.append(pa.table({"x": pa.array([], pa.int64())}))
assert getattr(tbl.inspect, method)() == tbl.inspect._get_files_schema().empty_table()
def test_inspect_files_of_snapshot_without_manifests(catalog: InMemoryCatalog) -> None:
tbl = catalog.create_table("default.no_manifests", Schema(NestedField(1, "x", LongType(), required=False)))
tbl.append(pa.table({"x": pa.array([], pa.int64())}))
expected = tbl.inspect._get_files_schema().empty_table()
for method in ["files", "data_files", "delete_files", "all_files", "all_data_files", "all_delete_files"]:
assert getattr(tbl.inspect, method)() == expected, method



def test_inspect_all_files_keeps_history_when_current_snapshot_has_no_manifests(catalog: InMemoryCatalog) -> None:
tbl = catalog.create_table("default.overwritten_with_empty", Schema(NestedField(1, "x", LongType(), required=False)))
tbl.append(pa.table({"x": pa.array([1], pa.int64())}))
tbl.overwrite(pa.table({"x": pa.array([], pa.int64())}))

assert tbl.inspect.files().num_rows == 0
assert tbl.inspect.all_files().num_rows == 1


@pytest.mark.parametrize("newest_first", [False, True])
def test_partitions_last_updated_uses_latest_snapshot_regardless_of_order(newest_first: bool) -> None:
# Manifest entries are visited in manifest order, which is not chronological, so the
Expand Down