Skip to content

perf: optimize table.add_files and inspect.files #2133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 22, 2025
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
2 changes: 1 addition & 1 deletion pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def add_files(
import pyarrow.compute as pc

expr = pc.field("file_path").isin(file_paths)
referenced_files = [file["file_path"] for file in self._table.inspect.files().filter(expr).to_pylist()]
referenced_files = [file["file_path"] for file in self._table.inspect.data_files().filter(expr).to_pylist()]

if referenced_files:
raise ValueError(f"Cannot add files that are already referenced by table, files: {', '.join(referenced_files)}")
Expand Down
11 changes: 7 additions & 4 deletions pyiceberg/table/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,14 @@ def _files(self, snapshot_id: Optional[int] = None, data_file_filter: Optional[S

snapshot = self._get_snapshot(snapshot_id)
io = self.tbl.io
files_table: list[pa.Table] = []
for manifest_list in snapshot.manifests(io):
files_table.append(self._get_files_from_manifest(manifest_list, data_file_filter))

return pa.concat_tables(files_table)
executor = ExecutorFactory.get_or_create()
results = list(
executor.map(
lambda manifest_list: self._get_files_from_manifest(manifest_list, data_file_filter), snapshot.manifests(io)
)
)
return pa.concat_tables(results)

def files(self, snapshot_id: Optional[int] = None) -> "pa.Table":
return self._files(snapshot_id)
Expand Down