Skip to content

Commit

Permalink
typealias for table version
Browse files Browse the repository at this point in the history
  • Loading branch information
MehulBatra committed Apr 1, 2024
1 parent bb8801e commit 64ec9ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions pyiceberg/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from pyiceberg.io import FileIO, InputFile, OutputFile
from pyiceberg.partitioning import PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.typedef import EMPTY_DICT, Record, VersionNumber
from pyiceberg.typedef import EMPTY_DICT, Record, TableVersion
from pyiceberg.types import (
BinaryType,
BooleanType,
Expand Down Expand Up @@ -302,7 +302,7 @@ def _(partition_field_type: PrimitiveType) -> PrimitiveType:
return partition_field_type


def data_file_with_partition(partition_type: StructType, format_version: VersionNumber) -> StructType:
def data_file_with_partition(partition_type: StructType, format_version: TableVersion) -> StructType:
data_file_partition_type = StructType(*[
NestedField(
field_id=field.field_id,
Expand Down Expand Up @@ -372,7 +372,7 @@ def __setattr__(self, name: str, value: Any) -> None:
value = FileFormat[value]
super().__setattr__(name, value)

def __init__(self, format_version: VersionNumber = DEFAULT_READ_VERSION, *data: Any, **named_data: Any) -> None:
def __init__(self, format_version: TableVersion = DEFAULT_READ_VERSION, *data: Any, **named_data: Any) -> None:
super().__init__(
*data,
**{"struct": DATA_FILE_TYPE[format_version], **named_data},
Expand Down Expand Up @@ -408,7 +408,7 @@ def __eq__(self, other: Any) -> bool:
MANIFEST_ENTRY_SCHEMAS_STRUCT = {format_version: schema.as_struct() for format_version, schema in MANIFEST_ENTRY_SCHEMAS.items()}


def manifest_entry_schema_with_data_file(format_version: VersionNumber, data_file: StructType) -> Schema:
def manifest_entry_schema_with_data_file(format_version: TableVersion, data_file: StructType) -> Schema:
return Schema(*[
NestedField(2, "data_file", data_file, required=True) if field.field_id == 2 else field
for field in MANIFEST_ENTRY_SCHEMAS[format_version].fields
Expand Down Expand Up @@ -719,9 +719,9 @@ def content(self) -> ManifestContent: ...

@property
@abstractmethod
def version(self) -> VersionNumber: ...
def version(self) -> TableVersion: ...

def _with_partition(self, format_version: VersionNumber) -> Schema:
def _with_partition(self, format_version: TableVersion) -> Schema:
data_file_type = data_file_with_partition(
format_version=format_version, partition_type=self._spec.partition_type(self._schema)
)
Expand Down Expand Up @@ -807,7 +807,7 @@ def content(self) -> ManifestContent:
return ManifestContent.DATA

@property
def version(self) -> VersionNumber:
def version(self) -> TableVersion:
return 1

def prepare_entry(self, entry: ManifestEntry) -> ManifestEntry:
Expand All @@ -834,7 +834,7 @@ def content(self) -> ManifestContent:
return ManifestContent.DATA

@property
def version(self) -> VersionNumber:
def version(self) -> TableVersion:
return 2

def prepare_entry(self, entry: ManifestEntry) -> ManifestEntry:
Expand All @@ -847,7 +847,7 @@ def prepare_entry(self, entry: ManifestEntry) -> ManifestEntry:


def write_manifest(
format_version: VersionNumber, spec: PartitionSpec, schema: Schema, output_file: OutputFile, snapshot_id: int
format_version: TableVersion, spec: PartitionSpec, schema: Schema, output_file: OutputFile, snapshot_id: int
) -> ManifestWriter:
if format_version == 1:
return ManifestWriterV1(spec, schema, output_file, snapshot_id)
Expand All @@ -858,14 +858,14 @@ def write_manifest(


class ManifestListWriter(ABC):
_format_version: VersionNumber
_format_version: TableVersion
_output_file: OutputFile
_meta: Dict[str, str]
_manifest_files: List[ManifestFile]
_commit_snapshot_id: int
_writer: AvroOutputFile[ManifestFile]

def __init__(self, format_version: VersionNumber, output_file: OutputFile, meta: Dict[str, Any]):
def __init__(self, format_version: TableVersion, output_file: OutputFile, meta: Dict[str, Any]):
self._format_version = format_version
self._output_file = output_file
self._meta = meta
Expand Down Expand Up @@ -957,7 +957,7 @@ def prepare_manifest(self, manifest_file: ManifestFile) -> ManifestFile:


def write_manifest_list(
format_version: VersionNumber,
format_version: TableVersion,
output_file: OutputFile,
snapshot_id: int,
parent_snapshot_id: Optional[int],
Expand Down
2 changes: 1 addition & 1 deletion pyiceberg/typedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ def record_fields(self) -> List[str]:
return [self.__getattribute__(v) if hasattr(self, v) else None for v in self._position_to_field_name]


VersionNumber = Literal[1, 2]
TableVersion = Literal[1, 2]

0 comments on commit 64ec9ff

Please sign in to comment.