@@ -88,7 +88,15 @@ class AddSchemaUpdate(IcebergBaseModel):
88
88
action : Literal ["add-schema" ] = Field (default = "add-schema" )
89
89
schema_ : Schema = Field (alias = "schema" )
90
90
# 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
+ )
92
100
93
101
initial_change : bool = Field (
94
102
default = False ,
@@ -318,11 +326,8 @@ def _(update: RemovePropertiesUpdate, base_metadata: TableMetadata, context: _Ta
318
326
319
327
@_apply_table_update .register (AddSchemaUpdate )
320
328
def _ (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
-
324
329
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 ) ,
326
331
"schemas" : base_metadata .schemas + [update .schema_ ],
327
332
}
328
333
0 commit comments