You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "gabeiglio (via GitHub)" <gi...@apache.org> on 2026/02/09 10:40:51 UTC

[PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

gabeiglio opened a new pull request, #3011:
URL: https://github.com/apache/iceberg-python/pull/3011

   <!--
   Thanks for opening a pull request!
   -->
   
   <!-- In the case this PR will resolve an issue, please replace ${GITHUB_ISSUE_ID} below with the actual Github issue id. -->
   <!-- Closes #${GITHUB_ISSUE_ID} -->
   
   # Rationale for this change
   
   Doing some performance tests for overwriting partitions, we noticed that PyIceberg took double the time it usually takes java based implementation, we noticed that `_exisiting_manifests` doe not take advantage of manifest pruning before reading all Manifest Entries 
   
   In this PR I:
   - Moved methods from _DeleteFiles to _SnapshotProducer parent class to share with other classes (_OverwriteFiles)
   - Implemented manifest pruning over all deleted files partitions to not read manifests that do not match file partitions
   - Refactored the method to only iterate once over all files (instead of multiple)
   
   ## Are these changes tested?
   
   I believe current tests in tests/integration/test_writes.py cover all cases
   
   ## Are there any user-facing changes?
   
   Nope
   
   <!-- In the case of user-facing changes, please add the changelog label. -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#issuecomment-3936756651

   Let's goo! Thanks @gabeiglio for working on this, this is super valuable. Thanks @geruh and @yingjianwu98 for the review 🚀 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko merged PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "gabeiglio (via GitHub)" <gi...@apache.org>.
gabeiglio commented on code in PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#discussion_r2826952573


##########
pyiceberg/table/update/snapshot.py:
##########
@@ -344,14 +331,20 @@ def _commit(self) -> UpdatesAndRequirements:
     def snapshot_id(self) -> int:
         return self._snapshot_id
 
+    def schema(self, schema_id: int | None = None) -> Schema:

Review Comment:
   removed 👍🏼 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "gabeiglio (via GitHub)" <gi...@apache.org>.
gabeiglio commented on code in PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#discussion_r2827075611


##########
pyiceberg/table/update/snapshot.py:
##########
@@ -51,9 +47,8 @@
     write_manifest,
     write_manifest_list,
 )
-from pyiceberg.partitioning import (
-    PartitionSpec,

Review Comment:
   its the linter, so every commit the pre-commit hook will flatten it again 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "yingjianwu98 (via GitHub)" <gi...@apache.org>.
yingjianwu98 commented on code in PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#discussion_r2824733984


##########
pyiceberg/table/update/snapshot.py:
##########
@@ -344,14 +331,20 @@ def _commit(self) -> UpdatesAndRequirements:
     def snapshot_id(self) -> int:
         return self._snapshot_id
 
+    def schema(self, schema_id: int | None = None) -> Schema:

Review Comment:
   nit: I don't see anywhere where we pass in the schema_id



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#discussion_r2825793016


##########
pyiceberg/table/__init__.py:
##########
@@ -396,16 +354,20 @@ def _set_ref_snapshot(
 
         return updates, requirements
 
-    def _build_partition_predicate(self, partition_records: set[Record]) -> BooleanExpression:
+    def _build_partition_predicate(

Review Comment:
   nit: Let's make the spec and schema non-optional, so the caller has to make the explicit choice what to pass down the the function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#discussion_r2829834392


##########
pyiceberg/table/update/snapshot.py:
##########
@@ -51,9 +47,8 @@
     write_manifest,
     write_manifest_list,
 )
-from pyiceberg.partitioning import (
-    PartitionSpec,

Review Comment:
   yeah looks cosmetic since it's linting alr committed code 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#discussion_r2825382122


##########
pyiceberg/table/update/snapshot.py:
##########
@@ -344,14 +331,20 @@ def _commit(self) -> UpdatesAndRequirements:
     def snapshot_id(self) -> int:
         return self._snapshot_id
 
+    def schema(self, schema_id: int | None = None) -> Schema:

Review Comment:
   +1 on dropping. without that this would just become `self._transaction.table_metadata.schema()`. 



##########
pyiceberg/table/update/snapshot.py:
##########
@@ -366,6 +359,35 @@ def new_manifest_output(self) -> OutputFile:
     def fetch_manifest_entry(self, manifest: ManifestFile, discard_deleted: bool = True) -> list[ManifestEntry]:
         return manifest.fetch_manifest_entry(io=self._io, discard_deleted=discard_deleted)
 
+    def _build_partition_projection(self, spec_id: int) -> BooleanExpression:
+        project = inclusive_projection(self.schema(), self.spec(spec_id), self._case_sensitive)
+        return project(self._predicate)
+
+    @cached_property
+    def partition_filters(self) -> KeyDefaultDict[int, BooleanExpression]:
+        return KeyDefaultDict(self._build_partition_projection)
+
+    def _build_manifest_evaluator(self, spec_id: int) -> Callable[[ManifestFile], bool]:
+        return manifest_evaluator(self.spec(spec_id), self.schema(), self.partition_filters[spec_id], self._case_sensitive)
+
+    def delete_by_predicate(self, predicate: BooleanExpression, case_sensitive: bool = True) -> None:
+        self._predicate = Or(self._predicate, predicate)
+        self._case_sensitive = case_sensitive
+
+    def _build_delete_files_partition_predicate(self) -> None:
+        """Build BooleanExpression based on deleted data files partitions."""
+        partition_to_overwrite: dict[int, set[Record]] = {}
+        for data_file in self._deleted_data_files:
+            group = partition_to_overwrite.setdefault(data_file.spec_id, set())
+            group.add(data_file.partition)
+
+        for spec_id, data_files in partition_to_overwrite.items():

Review Comment:
   nit:  
   ```suggestion
           for spec_id, partition_records in partition_to_overwrite.items():
   ```



##########
pyiceberg/table/update/snapshot.py:
##########
@@ -51,9 +47,8 @@
     write_manifest,
     write_manifest_list,
 )
-from pyiceberg.partitioning import (
-    PartitionSpec,

Review Comment:
   This moved a bunch of the imports to multi line for some reason



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "gabeiglio (via GitHub)" <gi...@apache.org>.
gabeiglio commented on code in PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#discussion_r2827002596


##########
pyiceberg/table/__init__.py:
##########
@@ -396,16 +354,20 @@ def _set_ref_snapshot(
 
         return updates, requirements
 
-    def _build_partition_predicate(self, partition_records: set[Record]) -> BooleanExpression:
+    def _build_partition_predicate(

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Optimization: Prune manifest in snapshot overwrite operations [iceberg-python]

Posted by "gabeiglio (via GitHub)" <gi...@apache.org>.
gabeiglio commented on code in PR #3011:
URL: https://github.com/apache/iceberg-python/pull/3011#discussion_r2826931047


##########
pyiceberg/table/update/snapshot.py:
##########
@@ -366,6 +359,35 @@ def new_manifest_output(self) -> OutputFile:
     def fetch_manifest_entry(self, manifest: ManifestFile, discard_deleted: bool = True) -> list[ManifestEntry]:
         return manifest.fetch_manifest_entry(io=self._io, discard_deleted=discard_deleted)
 
+    def _build_partition_projection(self, spec_id: int) -> BooleanExpression:
+        project = inclusive_projection(self.schema(), self.spec(spec_id), self._case_sensitive)
+        return project(self._predicate)
+
+    @cached_property
+    def partition_filters(self) -> KeyDefaultDict[int, BooleanExpression]:
+        return KeyDefaultDict(self._build_partition_projection)
+
+    def _build_manifest_evaluator(self, spec_id: int) -> Callable[[ManifestFile], bool]:
+        return manifest_evaluator(self.spec(spec_id), self.schema(), self.partition_filters[spec_id], self._case_sensitive)
+
+    def delete_by_predicate(self, predicate: BooleanExpression, case_sensitive: bool = True) -> None:
+        self._predicate = Or(self._predicate, predicate)
+        self._case_sensitive = case_sensitive
+
+    def _build_delete_files_partition_predicate(self) -> None:
+        """Build BooleanExpression based on deleted data files partitions."""
+        partition_to_overwrite: dict[int, set[Record]] = {}
+        for data_file in self._deleted_data_files:
+            group = partition_to_overwrite.setdefault(data_file.spec_id, set())
+            group.add(data_file.partition)
+
+        for spec_id, data_files in partition_to_overwrite.items():

Review Comment:
   ups, good catch



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org