1818
1919import uuid
2020from abc import ABC , abstractmethod
21- from copy import copy
2221from datetime import datetime
2322from functools import singledispatch
2423from typing import TYPE_CHECKING , Any , Dict , Generic , List , Literal , Optional , Tuple , TypeVar , Union
4544 transform_dict_value_to_str ,
4645)
4746from pyiceberg .utils .datetime import datetime_to_millis
47+ from pyiceberg .utils .deprecated import deprecation_notice
4848from pyiceberg .utils .properties import property_as_int
4949
5050if TYPE_CHECKING :
@@ -90,7 +90,13 @@ class AddSchemaUpdate(IcebergBaseModel):
9090 # This field is required: https://github.com/apache/iceberg/pull/7445
9191 last_column_id : int = Field (alias = "last-column-id" )
9292
93- initial_change : bool = Field (default = False , exclude = True )
93+ initial_change : bool = Field (
94+ default = False ,
95+ exclude = True ,
96+ deprecated = deprecation_notice (
97+ deprecated_in = "0.8.0" , removed_in = "0.9.0" , help_message = "CreateTableTransaction can work without this field"
98+ ),
99+ )
94100
95101
96102class SetCurrentSchemaUpdate (IcebergBaseModel ):
@@ -104,7 +110,13 @@ class AddPartitionSpecUpdate(IcebergBaseModel):
104110 action : Literal ["add-spec" ] = Field (default = "add-spec" )
105111 spec : PartitionSpec
106112
107- initial_change : bool = Field (default = False , exclude = True )
113+ initial_change : bool = Field (
114+ default = False ,
115+ exclude = True ,
116+ deprecated = deprecation_notice (
117+ deprecated_in = "0.8.0" , removed_in = "0.9.0" , help_message = "CreateTableTransaction can work without this field"
118+ ),
119+ )
108120
109121
110122class SetDefaultSpecUpdate (IcebergBaseModel ):
@@ -118,7 +130,13 @@ class AddSortOrderUpdate(IcebergBaseModel):
118130 action : Literal ["add-sort-order" ] = Field (default = "add-sort-order" )
119131 sort_order : SortOrder = Field (alias = "sort-order" )
120132
121- initial_change : bool = Field (default = False , exclude = True )
133+ initial_change : bool = Field (
134+ default = False ,
135+ exclude = True ,
136+ deprecated = deprecation_notice (
137+ deprecated_in = "0.8.0" , removed_in = "0.9.0" , help_message = "CreateTableTransaction can work without this field"
138+ ),
139+ )
122140
123141
124142class SetDefaultSortOrderUpdate (IcebergBaseModel ):
@@ -267,11 +285,10 @@ def _(
267285 elif update .format_version == base_metadata .format_version :
268286 return base_metadata
269287
270- updated_metadata_data = copy (base_metadata .model_dump ())
271- updated_metadata_data ["format-version" ] = update .format_version
288+ updated_metadata = base_metadata .model_copy (update = {"format_version" : update .format_version })
272289
273290 context .add_update (update )
274- return TableMetadataUtil .parse_obj ( updated_metadata_data )
291+ return TableMetadataUtil ._construct_without_validation ( updated_metadata )
275292
276293
277294@_apply_table_update .register (SetPropertiesUpdate )
@@ -306,7 +323,7 @@ def _(update: AddSchemaUpdate, base_metadata: TableMetadata, context: _TableMeta
306323
307324 metadata_updates : Dict [str , Any ] = {
308325 "last_column_id" : update .last_column_id ,
309- "schemas" : [ update . schema_ ] if update . initial_change else base_metadata .schemas + [update .schema_ ],
326+ "schemas" : base_metadata .schemas + [update .schema_ ],
310327 }
311328
312329 context .add_update (update )
@@ -336,11 +353,11 @@ def _(update: SetCurrentSchemaUpdate, base_metadata: TableMetadata, context: _Ta
336353@_apply_table_update .register (AddPartitionSpecUpdate )
337354def _ (update : AddPartitionSpecUpdate , base_metadata : TableMetadata , context : _TableMetadataUpdateContext ) -> TableMetadata :
338355 for spec in base_metadata .partition_specs :
339- if spec .spec_id == update .spec .spec_id and not update . initial_change :
356+ if spec .spec_id == update .spec .spec_id :
340357 raise ValueError (f"Partition spec with id { spec .spec_id } already exists: { spec } " )
341358
342359 metadata_updates : Dict [str , Any ] = {
343- "partition_specs" : [ update . spec ] if update . initial_change else base_metadata .partition_specs + [update .spec ],
360+ "partition_specs" : base_metadata .partition_specs + [update .spec ],
344361 "last_partition_id" : max (
345362 max ([field .field_id for field in update .spec .fields ], default = 0 ),
346363 base_metadata .last_partition_id or PARTITION_FIELD_ID_START - 1 ,
@@ -448,7 +465,7 @@ def _(update: AddSortOrderUpdate, base_metadata: TableMetadata, context: _TableM
448465 context .add_update (update )
449466 return base_metadata .model_copy (
450467 update = {
451- "sort_orders" : [ update . sort_order ] if update . initial_change else base_metadata .sort_orders + [update .sort_order ],
468+ "sort_orders" : base_metadata .sort_orders + [update .sort_order ],
452469 }
453470 )
454471
0 commit comments