rdblue commented on code in PR #5627:
URL: https://github.com/apache/iceberg/pull/5627#discussion_r954155497


##########
python/pyiceberg/schema.py:
##########
@@ -638,3 +640,61 @@ def map(self, map_type: MapType, key_result: int, 
value_result: int) -> int:
 
     def primitive(self, primitive: PrimitiveType) -> int:
         return 0
+
+
+def assign_fresh_schema_ids(schema: Schema) -> Schema:
+    """Traverses the schema, and sets new IDs"""
+    schema_struct = visit(schema.as_struct(), _SetFreshIDs())
+
+    fresh_identifier_field_ids = []
+    new_schema = Schema(*schema_struct.fields)
+    for field_id in schema.identifier_field_ids:
+        original_field = schema.find_field(field_id)
+        if original_field is None:
+            raise ValueError(f"Could not find field: {field_id}")
+        fresh_field = new_schema.find_field(original_field.name)
+        if fresh_field is None:
+            raise ValueError(f"Could not lookup field in new schema: 
{original_field}")
+        fresh_identifier_field_ids.append(fresh_field.field_id)
+
+    return new_schema.copy(update={"identifier_field_ids": 
fresh_identifier_field_ids})
+
+
+class _SetFreshIDs(SchemaVisitor[IcebergType]):
+    """Traverses the schema to get the highest field-id"""
+
+    counter: int
+
+    def __init__(self) -> None:
+        self.counter = 0

Review Comment:
   While this is technically okay, we don't assign ID 0 in other cases. It has 
been useful as a way to know that IDs in a schema aren't coming from 
reassignment and helps us catch errors. I'd recommend starting at 1 or changing 
assignment to `_increment_and_get`.



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