57
57
TABLE_ROOT_ID = - 1
58
58
59
59
60
- class MoveOperation (Enum ):
60
+ class _MoveOperation (Enum ):
61
61
First = 1
62
62
Before = 2
63
63
After = 3
64
64
65
65
66
66
@dataclass
67
- class Move :
67
+ class _Move :
68
68
field_id : int
69
69
full_name : str
70
- op : MoveOperation
70
+ op : _MoveOperation
71
71
other_field_id : Optional [int ] = None
72
72
73
73
@@ -79,7 +79,7 @@ class UpdateSchema(UpdateTableMetadata["UpdateSchema"]):
79
79
_adds : Dict [int , List [NestedField ]] = {}
80
80
_updates : Dict [int , NestedField ] = {}
81
81
_deletes : Set [int ] = set ()
82
- _moves : Dict [int , List [Move ]] = {}
82
+ _moves : Dict [int , List [_Move ]] = {}
83
83
84
84
_added_name_to_id : Dict [str , int ] = {}
85
85
# 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:
146
146
visit_with_partner (
147
147
Catalog ._convert_schema_if_needed (new_schema ),
148
148
- 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 ),
150
150
# type: ignore
151
151
PartnerIdByNameAccessor (partner_schema = self ._schema , case_sensitive = self ._case_sensitive ),
152
152
)
@@ -410,13 +410,13 @@ def _find_for_move(self, name: str) -> Optional[int]:
410
410
411
411
return self ._added_name_to_id .get (name )
412
412
413
- def _move (self , move : Move ) -> None :
413
+ def _move (self , move : _Move ) -> None :
414
414
if parent_name := self ._id_to_parent .get (move .field_id ):
415
415
parent_field = self ._schema .find_field (parent_name , case_sensitive = self ._case_sensitive )
416
416
if not parent_field .field_type .is_struct :
417
417
raise ValueError (f"Cannot move fields in non-struct type: { parent_field .field_type } " )
418
418
419
- if move .op == MoveOperation .After or move .op == MoveOperation .Before :
419
+ if move .op == _MoveOperation .After or move .op == _MoveOperation .Before :
420
420
if move .other_field_id is None :
421
421
raise ValueError ("Expected other field when performing before/after move" )
422
422
@@ -426,7 +426,7 @@ def _move(self, move: Move) -> None:
426
426
self ._moves [parent_field .field_id ] = self ._moves .get (parent_field .field_id , []) + [move ]
427
427
else :
428
428
# 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 :
430
430
if move .other_field_id is None :
431
431
raise ValueError ("Expected other field when performing before/after move" )
432
432
@@ -451,7 +451,7 @@ def move_first(self, path: Union[str, Tuple[str, ...]]) -> UpdateSchema:
451
451
if field_id is None :
452
452
raise ValueError (f"Cannot move missing column: { full_name } " )
453
453
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 ))
455
455
456
456
return self
457
457
@@ -485,7 +485,7 @@ def move_before(self, path: Union[str, Tuple[str, ...]], before_path: Union[str,
485
485
if field_id == before_field_id :
486
486
raise ValueError (f"Cannot move { full_name } before itself" )
487
487
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 ))
489
489
490
490
return self
491
491
@@ -514,7 +514,7 @@ def move_after(self, path: Union[str, Tuple[str, ...]], after_name: Union[str, T
514
514
if field_id == after_field_id :
515
515
raise ValueError (f"Cannot move { full_name } after itself" )
516
516
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 ))
518
518
519
519
return self
520
520
@@ -592,10 +592,14 @@ class _ApplyChanges(SchemaVisitor[Optional[IcebergType]]):
592
592
_adds : Dict [int , List [NestedField ]]
593
593
_updates : Dict [int , NestedField ]
594
594
_deletes : Set [int ]
595
- _moves : Dict [int , List [Move ]]
595
+ _moves : Dict [int , List [_Move ]]
596
596
597
597
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 ]],
599
603
) -> None :
600
604
self ._adds = adds
601
605
self ._updates = updates
@@ -715,7 +719,7 @@ def primitive(self, primitive: PrimitiveType) -> Optional[IcebergType]:
715
719
return primitive
716
720
717
721
718
- class UnionByNameVisitor (SchemaWithPartnerVisitor [int , bool ]):
722
+ class _UnionByNameVisitor (SchemaWithPartnerVisitor [int , bool ]):
719
723
update_schema : UpdateSchema
720
724
existing_schema : Schema
721
725
case_sensitive : bool
@@ -873,20 +877,20 @@ def _add_fields(fields: Tuple[NestedField, ...], adds: Optional[List[NestedField
873
877
return fields + tuple (adds )
874
878
875
879
876
- def _move_fields (fields : Tuple [NestedField , ...], moves : List [Move ]) -> Tuple [NestedField , ...]:
880
+ def _move_fields (fields : Tuple [NestedField , ...], moves : List [_Move ]) -> Tuple [NestedField , ...]:
877
881
reordered = list (copy (fields ))
878
882
for move in moves :
879
883
# Find the field that we're about to move
880
884
field = next (field for field in reordered if field .field_id == move .field_id )
881
885
# Remove the field that we're about to move from the list
882
886
reordered = [field for field in reordered if field .field_id != move .field_id ]
883
887
884
- if move .op == MoveOperation .First :
888
+ if move .op == _MoveOperation .First :
885
889
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 :
887
891
other_field_id = move .other_field_id
888
892
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 :
890
894
reordered .insert (other_field_pos , field )
891
895
else :
892
896
reordered .insert (other_field_pos + 1 , field )
@@ -897,7 +901,7 @@ def _move_fields(fields: Tuple[NestedField, ...], moves: List[Move]) -> Tuple[Ne
897
901
898
902
899
903
def _add_and_move_fields (
900
- fields : Tuple [NestedField , ...], adds : List [NestedField ], moves : List [Move ]
904
+ fields : Tuple [NestedField , ...], adds : List [NestedField ], moves : List [_Move ]
901
905
) -> Optional [Tuple [NestedField , ...]]:
902
906
if len (adds ) > 0 :
903
907
# always apply adds first so that added fields can be moved
0 commit comments