37
37
from pyiceberg .io import FileIO , InputFile , OutputFile
38
38
from pyiceberg .partitioning import PartitionSpec
39
39
from pyiceberg .schema import Schema
40
- from pyiceberg .typedef import EMPTY_DICT , Record
40
+ from pyiceberg .typedef import EMPTY_DICT , Record , TableVersion
41
41
from pyiceberg .types import (
42
42
BinaryType ,
43
43
BooleanType ,
@@ -302,7 +302,7 @@ def _(partition_field_type: PrimitiveType) -> PrimitiveType:
302
302
return partition_field_type
303
303
304
304
305
- def data_file_with_partition (partition_type : StructType , format_version : Literal [ 1 , 2 ] ) -> StructType :
305
+ def data_file_with_partition (partition_type : StructType , format_version : TableVersion ) -> StructType :
306
306
data_file_partition_type = StructType (* [
307
307
NestedField (
308
308
field_id = field .field_id ,
@@ -372,7 +372,7 @@ def __setattr__(self, name: str, value: Any) -> None:
372
372
value = FileFormat [value ]
373
373
super ().__setattr__ (name , value )
374
374
375
- def __init__ (self , format_version : Literal [ 1 , 2 ] = DEFAULT_READ_VERSION , * data : Any , ** named_data : Any ) -> None :
375
+ def __init__ (self , format_version : TableVersion = DEFAULT_READ_VERSION , * data : Any , ** named_data : Any ) -> None :
376
376
super ().__init__ (
377
377
* data ,
378
378
** {"struct" : DATA_FILE_TYPE [format_version ], ** named_data },
@@ -408,7 +408,7 @@ def __eq__(self, other: Any) -> bool:
408
408
MANIFEST_ENTRY_SCHEMAS_STRUCT = {format_version : schema .as_struct () for format_version , schema in MANIFEST_ENTRY_SCHEMAS .items ()}
409
409
410
410
411
- def manifest_entry_schema_with_data_file (format_version : Literal [ 1 , 2 ] , data_file : StructType ) -> Schema :
411
+ def manifest_entry_schema_with_data_file (format_version : TableVersion , data_file : StructType ) -> Schema :
412
412
return Schema (* [
413
413
NestedField (2 , "data_file" , data_file , required = True ) if field .field_id == 2 else field
414
414
for field in MANIFEST_ENTRY_SCHEMAS [format_version ].fields
@@ -719,9 +719,9 @@ def content(self) -> ManifestContent: ...
719
719
720
720
@property
721
721
@abstractmethod
722
- def version (self ) -> Literal [ 1 , 2 ] : ...
722
+ def version (self ) -> TableVersion : ...
723
723
724
- def _with_partition (self , format_version : Literal [ 1 , 2 ] ) -> Schema :
724
+ def _with_partition (self , format_version : TableVersion ) -> Schema :
725
725
data_file_type = data_file_with_partition (
726
726
format_version = format_version , partition_type = self ._spec .partition_type (self ._schema )
727
727
)
@@ -807,7 +807,7 @@ def content(self) -> ManifestContent:
807
807
return ManifestContent .DATA
808
808
809
809
@property
810
- def version (self ) -> Literal [ 1 , 2 ] :
810
+ def version (self ) -> TableVersion :
811
811
return 1
812
812
813
813
def prepare_entry (self , entry : ManifestEntry ) -> ManifestEntry :
@@ -834,7 +834,7 @@ def content(self) -> ManifestContent:
834
834
return ManifestContent .DATA
835
835
836
836
@property
837
- def version (self ) -> Literal [ 1 , 2 ] :
837
+ def version (self ) -> TableVersion :
838
838
return 2
839
839
840
840
def prepare_entry (self , entry : ManifestEntry ) -> ManifestEntry :
@@ -847,7 +847,7 @@ def prepare_entry(self, entry: ManifestEntry) -> ManifestEntry:
847
847
848
848
849
849
def write_manifest (
850
- format_version : Literal [ 1 , 2 ] , spec : PartitionSpec , schema : Schema , output_file : OutputFile , snapshot_id : int
850
+ format_version : TableVersion , spec : PartitionSpec , schema : Schema , output_file : OutputFile , snapshot_id : int
851
851
) -> ManifestWriter :
852
852
if format_version == 1 :
853
853
return ManifestWriterV1 (spec , schema , output_file , snapshot_id )
@@ -858,14 +858,14 @@ def write_manifest(
858
858
859
859
860
860
class ManifestListWriter (ABC ):
861
- _format_version : Literal [ 1 , 2 ]
861
+ _format_version : TableVersion
862
862
_output_file : OutputFile
863
863
_meta : Dict [str , str ]
864
864
_manifest_files : List [ManifestFile ]
865
865
_commit_snapshot_id : int
866
866
_writer : AvroOutputFile [ManifestFile ]
867
867
868
- def __init__ (self , format_version : Literal [ 1 , 2 ] , output_file : OutputFile , meta : Dict [str , Any ]):
868
+ def __init__ (self , format_version : TableVersion , output_file : OutputFile , meta : Dict [str , Any ]):
869
869
self ._format_version = format_version
870
870
self ._output_file = output_file
871
871
self ._meta = meta
@@ -957,7 +957,7 @@ def prepare_manifest(self, manifest_file: ManifestFile) -> ManifestFile:
957
957
958
958
959
959
def write_manifest_list (
960
- format_version : Literal [ 1 , 2 ] ,
960
+ format_version : TableVersion ,
961
961
output_file : OutputFile ,
962
962
snapshot_id : int ,
963
963
parent_snapshot_id : Optional [int ],
0 commit comments