5757TABLE_ROOT_ID = - 1
5858
5959
60- class MoveOperation (Enum ):
60+ class _MoveOperation (Enum ):
6161 First = 1
6262 Before = 2
6363 After = 3
6464
6565
6666@dataclass
67- class Move :
67+ class _Move :
6868 field_id : int
6969 full_name : str
70- op : MoveOperation
70+ op : _MoveOperation
7171 other_field_id : Optional [int ] = None
7272
7373
@@ -79,7 +79,7 @@ class UpdateSchema(UpdateTableMetadata["UpdateSchema"]):
7979 _adds : Dict [int , List [NestedField ]] = {}
8080 _updates : Dict [int , NestedField ] = {}
8181 _deletes : Set [int ] = set ()
82- _moves : Dict [int , List [Move ]] = {}
82+ _moves : Dict [int , List [_Move ]] = {}
8383
8484 _added_name_to_id : Dict [str , int ] = {}
8585 # Part of https://github.com/apache/iceberg/pull/8393
@@ -146,7 +146,7 @@ def union_by_name(self, new_schema: Union[Schema, "pa.Schema"]) -> UpdateSchema:
146146 visit_with_partner (
147147 Catalog ._convert_schema_if_needed (new_schema ),
148148 - 1 ,
149- UnionByNameVisitor (update_schema = self , existing_schema = self ._schema , case_sensitive = self ._case_sensitive ),
149+ _UnionByNameVisitor (update_schema = self , existing_schema = self ._schema , case_sensitive = self ._case_sensitive ),
150150 # type: ignore
151151 PartnerIdByNameAccessor (partner_schema = self ._schema , case_sensitive = self ._case_sensitive ),
152152 )
@@ -410,13 +410,13 @@ def _find_for_move(self, name: str) -> Optional[int]:
410410
411411 return self ._added_name_to_id .get (name )
412412
413- def _move (self , move : Move ) -> None :
413+ def _move (self , move : _Move ) -> None :
414414 if parent_name := self ._id_to_parent .get (move .field_id ):
415415 parent_field = self ._schema .find_field (parent_name , case_sensitive = self ._case_sensitive )
416416 if not parent_field .field_type .is_struct :
417417 raise ValueError (f"Cannot move fields in non-struct type: { parent_field .field_type } " )
418418
419- if move .op == MoveOperation .After or move .op == MoveOperation .Before :
419+ if move .op == _MoveOperation .After or move .op == _MoveOperation .Before :
420420 if move .other_field_id is None :
421421 raise ValueError ("Expected other field when performing before/after move" )
422422
@@ -426,7 +426,7 @@ def _move(self, move: Move) -> None:
426426 self ._moves [parent_field .field_id ] = self ._moves .get (parent_field .field_id , []) + [move ]
427427 else :
428428 # In the top level field
429- if move .op == MoveOperation .After or move .op == MoveOperation .Before :
429+ if move .op == _MoveOperation .After or move .op == _MoveOperation .Before :
430430 if move .other_field_id is None :
431431 raise ValueError ("Expected other field when performing before/after move" )
432432
@@ -451,7 +451,7 @@ def move_first(self, path: Union[str, Tuple[str, ...]]) -> UpdateSchema:
451451 if field_id is None :
452452 raise ValueError (f"Cannot move missing column: { full_name } " )
453453
454- self ._move (Move (field_id = field_id , full_name = full_name , op = MoveOperation .First ))
454+ self ._move (_Move (field_id = field_id , full_name = full_name , op = _MoveOperation .First ))
455455
456456 return self
457457
@@ -485,7 +485,7 @@ def move_before(self, path: Union[str, Tuple[str, ...]], before_path: Union[str,
485485 if field_id == before_field_id :
486486 raise ValueError (f"Cannot move { full_name } before itself" )
487487
488- self ._move (Move (field_id = field_id , full_name = full_name , other_field_id = before_field_id , op = MoveOperation .Before ))
488+ self ._move (_Move (field_id = field_id , full_name = full_name , other_field_id = before_field_id , op = _MoveOperation .Before ))
489489
490490 return self
491491
@@ -514,7 +514,7 @@ def move_after(self, path: Union[str, Tuple[str, ...]], after_name: Union[str, T
514514 if field_id == after_field_id :
515515 raise ValueError (f"Cannot move { full_name } after itself" )
516516
517- self ._move (Move (field_id = field_id , full_name = full_name , other_field_id = after_field_id , op = MoveOperation .After ))
517+ self ._move (_Move (field_id = field_id , full_name = full_name , other_field_id = after_field_id , op = _MoveOperation .After ))
518518
519519 return self
520520
@@ -592,10 +592,14 @@ class _ApplyChanges(SchemaVisitor[Optional[IcebergType]]):
592592 _adds : Dict [int , List [NestedField ]]
593593 _updates : Dict [int , NestedField ]
594594 _deletes : Set [int ]
595- _moves : Dict [int , List [Move ]]
595+ _moves : Dict [int , List [_Move ]]
596596
597597 def __init__ (
598- self , adds : Dict [int , List [NestedField ]], updates : Dict [int , NestedField ], deletes : Set [int ], moves : Dict [int , List [Move ]]
598+ self ,
599+ adds : Dict [int , List [NestedField ]],
600+ updates : Dict [int , NestedField ],
601+ deletes : Set [int ],
602+ moves : Dict [int , List [_Move ]],
599603 ) -> None :
600604 self ._adds = adds
601605 self ._updates = updates
@@ -715,7 +719,7 @@ def primitive(self, primitive: PrimitiveType) -> Optional[IcebergType]:
715719 return primitive
716720
717721
718- class UnionByNameVisitor (SchemaWithPartnerVisitor [int , bool ]):
722+ class _UnionByNameVisitor (SchemaWithPartnerVisitor [int , bool ]):
719723 update_schema : UpdateSchema
720724 existing_schema : Schema
721725 case_sensitive : bool
@@ -873,20 +877,20 @@ def _add_fields(fields: Tuple[NestedField, ...], adds: Optional[List[NestedField
873877 return fields + tuple (adds )
874878
875879
876- def _move_fields (fields : Tuple [NestedField , ...], moves : List [Move ]) -> Tuple [NestedField , ...]:
880+ def _move_fields (fields : Tuple [NestedField , ...], moves : List [_Move ]) -> Tuple [NestedField , ...]:
877881 reordered = list (copy (fields ))
878882 for move in moves :
879883 # Find the field that we're about to move
880884 field = next (field for field in reordered if field .field_id == move .field_id )
881885 # Remove the field that we're about to move from the list
882886 reordered = [field for field in reordered if field .field_id != move .field_id ]
883887
884- if move .op == MoveOperation .First :
888+ if move .op == _MoveOperation .First :
885889 reordered = [field ] + reordered
886- elif move .op == MoveOperation .Before or move .op == MoveOperation .After :
890+ elif move .op == _MoveOperation .Before or move .op == _MoveOperation .After :
887891 other_field_id = move .other_field_id
888892 other_field_pos = next (i for i , field in enumerate (reordered ) if field .field_id == other_field_id )
889- if move .op == MoveOperation .Before :
893+ if move .op == _MoveOperation .Before :
890894 reordered .insert (other_field_pos , field )
891895 else :
892896 reordered .insert (other_field_pos + 1 , field )
@@ -897,7 +901,7 @@ def _move_fields(fields: Tuple[NestedField, ...], moves: List[Move]) -> Tuple[Ne
897901
898902
899903def _add_and_move_fields (
900- fields : Tuple [NestedField , ...], adds : List [NestedField ], moves : List [Move ]
904+ fields : Tuple [NestedField , ...], adds : List [NestedField ], moves : List [_Move ]
901905) -> Optional [Tuple [NestedField , ...]]:
902906 if len (adds ) > 0 :
903907 # always apply adds first so that added fields can be moved
0 commit comments