smaheshwar-pltr commented on code in PR #3220:
URL: https://github.com/apache/iceberg-python/pull/3220#discussion_r3106472778


##########
pyiceberg/table/__init__.py:
##########
@@ -1009,6 +1010,131 @@ def commit_transaction(self) -> Table:
         return self._table
 
 
+class ReplaceTableTransaction(Transaction):
+    """A transaction that replaces an existing table's schema, spec, sort 
order, location, and properties.
+
+    The existing table UUID, snapshots, snapshot log, metadata log, and 
history are preserved.
+    The "main" branch ref is removed (current-snapshot-id set to -1), and new
+    schema/spec/sort-order/location/properties are applied.
+    """
+
+    def _initial_changes(
+        self,
+        table_metadata: TableMetadata,
+        new_schema: Schema,
+        new_spec: PartitionSpec,
+        new_sort_order: SortOrder,
+        new_location: str,
+        new_properties: Properties,
+    ) -> None:
+        """Set the initial changes that transform the existing table into the 
replacement."""
+        # Remove the main branch ref to clear the current snapshot
+        self._updates += (RemoveSnapshotRefUpdate(ref_name=MAIN_BRANCH),)
+
+        # Set the new schema, reusing an existing schema if structurally 
identical.
+        # Schema.__eq__ compares fields and identifier_field_ids (ignoring 
schema_id),
+        # matching Java's sameSchema() behavior.
+        existing_schema_id = self._find_matching_schema_id(table_metadata, 
new_schema)
+        if existing_schema_id is not None:
+            if existing_schema_id != table_metadata.current_schema_id:
+                self._updates += 
(SetCurrentSchemaUpdate(schema_id=existing_schema_id),)
+        else:
+            self._updates += (
+                AddSchemaUpdate(schema_=new_schema),
+                SetCurrentSchemaUpdate(schema_id=-1),
+            )
+
+        # Set the new partition spec.
+        # Only emit AddPartitionSpecUpdate + SetDefaultSpecUpdate(-1) when the 
spec
+        # is genuinely new. If an identical spec already exists, use its 
concrete ID

Review Comment:
   Done.



##########
pyiceberg/table/__init__.py:
##########
@@ -1009,6 +1010,131 @@ def commit_transaction(self) -> Table:
         return self._table
 
 
+class ReplaceTableTransaction(Transaction):
+    """A transaction that replaces an existing table's schema, spec, sort 
order, location, and properties.
+
+    The existing table UUID, snapshots, snapshot log, metadata log, and 
history are preserved.
+    The "main" branch ref is removed (current-snapshot-id set to -1), and new
+    schema/spec/sort-order/location/properties are applied.
+    """
+
+    def _initial_changes(
+        self,
+        table_metadata: TableMetadata,
+        new_schema: Schema,
+        new_spec: PartitionSpec,
+        new_sort_order: SortOrder,
+        new_location: str,
+        new_properties: Properties,
+    ) -> None:
+        """Set the initial changes that transform the existing table into the 
replacement."""
+        # Remove the main branch ref to clear the current snapshot
+        self._updates += (RemoveSnapshotRefUpdate(ref_name=MAIN_BRANCH),)
+
+        # Set the new schema, reusing an existing schema if structurally 
identical.
+        # Schema.__eq__ compares fields and identifier_field_ids (ignoring 
schema_id),
+        # matching Java's sameSchema() behavior.

Review Comment:
   Done.



-- 
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]

Reply via email to