@@ -88,7 +88,15 @@ class AddSchemaUpdate(IcebergBaseModel):
8888 action : Literal ["add-schema" ] = Field (default = "add-schema" )
8989 schema_ : Schema = Field (alias = "schema" )
9090 # This field is required: https://github.com/apache/iceberg/pull/7445
91- last_column_id : int = Field (alias = "last-column-id" )
91+ last_column_id : Optional [int ] = Field (
92+ alias = "last-column-id" ,
93+ default = None ,
94+ deprecated = deprecation_notice (
95+ deprecated_in = "0.9.0" ,
96+ removed_in = "0.10.0" ,
97+ help_message = "last-field-id is handled internally, and should not be part of the update." ,
98+ ),
99+ )
92100
93101 initial_change : bool = Field (
94102 default = False ,
@@ -318,11 +326,8 @@ def _(update: RemovePropertiesUpdate, base_metadata: TableMetadata, context: _Ta
318326
319327@_apply_table_update .register (AddSchemaUpdate )
320328def _ (update : AddSchemaUpdate , base_metadata : TableMetadata , context : _TableMetadataUpdateContext ) -> TableMetadata :
321- if update .last_column_id < base_metadata .last_column_id :
322- raise ValueError (f"Invalid last column id { update .last_column_id } , must be >= { base_metadata .last_column_id } " )
323-
324329 metadata_updates : Dict [str , Any ] = {
325- "last_column_id" : update .last_column_id ,
330+ "last_column_id" : max ( base_metadata .last_column_id , update . schema_ . highest_field_id ) ,
326331 "schemas" : base_metadata .schemas + [update .schema_ ],
327332 }
328333
0 commit comments