@@ -193,6 +193,11 @@ class RemoveStatisticsUpdate(IcebergBaseModel):
193193 snapshot_id : int = Field (alias = "snapshot-id" )
194194
195195
196+ class RemoveSchemasUpdate (IcebergBaseModel ):
197+ action : Literal ["remove-schemas" ] = Field (default = "remove-schemas" )
198+ schema_ids : List [int ] = Field (alias = "schema-ids" )
199+
200+
196201class SetPartitionStatisticsUpdate (IcebergBaseModel ):
197202 action : Literal ["set-partition-statistics" ] = Field (default = "set-partition-statistics" )
198203 partition_statistics : PartitionStatisticsFile
@@ -222,6 +227,7 @@ class RemovePartitionStatisticsUpdate(IcebergBaseModel):
222227 RemovePropertiesUpdate ,
223228 SetStatisticsUpdate ,
224229 RemoveStatisticsUpdate ,
230+ RemoveSchemasUpdate ,
225231 SetPartitionStatisticsUpdate ,
226232 RemovePartitionStatisticsUpdate ,
227233 ],
@@ -589,6 +595,23 @@ def _(update: RemoveStatisticsUpdate, base_metadata: TableMetadata, context: _Ta
589595 return base_metadata .model_copy (update = {"statistics" : statistics })
590596
591597
598+ @_apply_table_update .register (RemoveSchemasUpdate )
599+ def _ (update : RemoveSchemasUpdate , base_metadata : TableMetadata , context : _TableMetadataUpdateContext ) -> TableMetadata :
600+ # This method should error if any schemas do not exist.
601+ # It should error if the default schema is being removed.
602+ # Otherwise, remove the schemas listed in update.schema_ids.
603+ for remove_schema_id in update .schema_ids :
604+ if not any (schema .schema_id == remove_schema_id for schema in base_metadata .schemas ):
605+ raise ValueError (f"Schema with schema id { remove_schema_id } does not exist" )
606+ if base_metadata .current_schema_id == remove_schema_id :
607+ raise ValueError (f"Cannot remove current schema with id { remove_schema_id } " )
608+
609+ schemas = [schema for schema in base_metadata .schemas if schema .schema_id not in update .schema_ids ]
610+ context .add_update (update )
611+
612+ return base_metadata .model_copy (update = {"schemas" : schemas })
613+
614+
592615@_apply_table_update .register (SetPartitionStatisticsUpdate )
593616def _ (update : SetPartitionStatisticsUpdate , base_metadata : TableMetadata , context : _TableMetadataUpdateContext ) -> TableMetadata :
594617 partition_statistics = filter_statistics_by_snapshot_id (
0 commit comments