qzyu999 commented on code in PR #3131:
URL: https://github.com/apache/iceberg-python/pull/3131#discussion_r3983944830
##########
pyiceberg/table/update/snapshot.py:
##########
@@ -852,6 +850,120 @@ def _get_entries(manifest: ManifestFile) ->
list[ManifestEntry]:
return []
+class _RewriteFiles(_SnapshotProducer["_RewriteFiles"]):
+ """A snapshot producer that rewrites data files.
+
+ Produces a REPLACE snapshot that swaps existing data files for new ones
without
+ changing the logical contents of the table. This is the metadata-only
operation
+ used by compaction (bin-packing, sort, format migration).
+
+ Current scope:
+ - Data file rewriting only (delete + add DataFiles)
+ - Validates: files-to-delete exist, added_records <= deleted_records,
+ no new delete files conflict with replaced data files
+
+ Future work (additive — no structural changes needed):
+ - Delete-file rewriting (add _deleted_delete_files set + separate
manifest handling)
+ - dataSequenceNumber override (pin new files' seq to match replaced,
for eq-delete safety)
+ - validateFromSnapshot (expose _starting_snapshot_id setter for
long-running planners)
+ - ignoreEqualityDeletes in validation (coupled with dataSequenceNumber)
+ """
+
+ def _commit(self) -> UpdatesAndRequirements:
+ # Only produce a commit when there is something to rewrite
+ if self._deleted_data_files or self._added_data_files:
Review Comment:
Thanks @rambleraptor, I've flattened `_commit()` into guard-clause style:
the no-op early return is now at the top, and the rest is a flat sequence of
`if invariant -> raise` checks ending with `super()._commit()`. I think the
code suggestion has a small logic flip (`not deleted and added` vs `not deleted
and not added`) but the structural feedback is addressed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]