@@ -198,6 +198,11 @@ class RemoveStatisticsUpdate(IcebergBaseModel):
198198 snapshot_id : int = Field (alias = "snapshot-id" )
199199
200200
201+ class RemoveSchemasUpdate (IcebergBaseModel ):
202+ action : Literal ["remove-schemas" ] = Field (default = "remove-schemas" )
203+ schema_ids : List [int ] = Field (alias = "schema-ids" )
204+
205+
201206TableUpdate = Annotated [
202207 Union [
203208 AssignUUIDUpdate ,
@@ -217,6 +222,7 @@ class RemoveStatisticsUpdate(IcebergBaseModel):
217222 RemovePropertiesUpdate ,
218223 SetStatisticsUpdate ,
219224 RemoveStatisticsUpdate ,
225+ RemoveSchemasUpdate ,
220226 ],
221227 Field (discriminator = "action" ),
222228]
@@ -582,6 +588,23 @@ def _(update: RemoveStatisticsUpdate, base_metadata: TableMetadata, context: _Ta
582588 return base_metadata .model_copy (update = {"statistics" : statistics })
583589
584590
591+ @_apply_table_update .register (RemoveSchemasUpdate )
592+ def _ (update : RemoveSchemasUpdate , base_metadata : TableMetadata , context : _TableMetadataUpdateContext ) -> TableMetadata :
593+ # This method should error if any schemas do not exist.
594+ # It should error if the default schema is being removed.
595+ # Otherwise, remove the schemas listed in update.schema_ids.
596+ for remove_schema_id in update .schema_ids :
597+ if not any (schema .schema_id == remove_schema_id for schema in base_metadata .schemas ):
598+ raise ValueError (f"Schema with schema id { remove_schema_id } does not exist" )
599+ if base_metadata .current_schema_id == remove_schema_id :
600+ raise ValueError (f"Cannot remove current schema with id { remove_schema_id } " )
601+
602+ schemas = [schema for schema in base_metadata .schemas if schema .schema_id not in update .schema_ids ]
603+ context .add_update (update )
604+
605+ return base_metadata .model_copy (update = {"schemas" : schemas })
606+
607+
585608def update_table_metadata (
586609 base_metadata : TableMetadata ,
587610 updates : Tuple [TableUpdate , ...],
0 commit comments