This is an automated email from the ASF dual-hosted git repository.
etudenhoefner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new 3648b041ac Python: Small fixes (#7989)
3648b041ac is described below
commit 3648b041acb8e29289e0c50bbbf60cbbae63917a
Author: Fokko Driesprong <[email protected]>
AuthorDate: Tue Jul 25 08:55:07 2023 +0200
Python: Small fixes (#7989)
Uncovered these when upgrading to Pydantic 2.0
---
python/pyiceberg/table/__init__.py | 28 ++++++++++++++--------------
python/pyiceberg/table/metadata.py | 2 +-
python/pyiceberg/table/snapshots.py | 10 ++++++----
python/tests/catalog/test_hive.py | 4 ++--
python/tests/table/test_init.py | 4 ++--
python/tests/table/test_metadata.py | 2 +-
6 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/python/pyiceberg/table/__init__.py
b/python/pyiceberg/table/__init__.py
index 773ac38e89..997729c239 100644
--- a/python/pyiceberg/table/__init__.py
+++ b/python/pyiceberg/table/__init__.py
@@ -220,53 +220,53 @@ class TableUpdate(IcebergBaseModel):
class UpgradeFormatVersionUpdate(TableUpdate):
- action = TableUpdateAction.upgrade_format_version
+ action: TableUpdateAction = TableUpdateAction.upgrade_format_version
format_version: int = Field(alias="format-version")
class AddSchemaUpdate(TableUpdate):
- action = TableUpdateAction.add_schema
+ action: TableUpdateAction = TableUpdateAction.add_schema
schema_: Schema = Field(alias="schema")
class SetCurrentSchemaUpdate(TableUpdate):
- action = TableUpdateAction.set_current_schema
+ action: TableUpdateAction = TableUpdateAction.set_current_schema
schema_id: int = Field(
alias="schema-id", description="Schema ID to set as current, or -1 to
set last added schema", default=-1
)
class AddPartitionSpecUpdate(TableUpdate):
- action = TableUpdateAction.add_spec
+ action: TableUpdateAction = TableUpdateAction.add_spec
spec: PartitionSpec
class SetDefaultSpecUpdate(TableUpdate):
- action = TableUpdateAction.set_default_spec
+ action: TableUpdateAction = TableUpdateAction.set_default_spec
spec_id: int = Field(
alias="spec-id", description="Partition spec ID to set as the default,
or -1 to set last added spec", default=-1
)
class AddSortOrderUpdate(TableUpdate):
- action = TableUpdateAction.add_sort_order
+ action: TableUpdateAction = TableUpdateAction.add_sort_order
sort_order: SortOrder = Field(alias="sort-order")
class SetDefaultSortOrderUpdate(TableUpdate):
- action = TableUpdateAction.set_default_sort_order
+ action: TableUpdateAction = TableUpdateAction.set_default_sort_order
sort_order_id: int = Field(
alias="sort-order-id", description="Sort order ID to set as the
default, or -1 to set last added sort order", default=-1
)
class AddSnapshotUpdate(TableUpdate):
- action = TableUpdateAction.add_snapshot
+ action: TableUpdateAction = TableUpdateAction.add_snapshot
snapshot: Snapshot
class SetSnapshotRefUpdate(TableUpdate):
- action = TableUpdateAction.set_snapshot_ref
+ action: TableUpdateAction = TableUpdateAction.set_snapshot_ref
ref_name: str = Field(alias="ref-name")
type: Literal["tag", "branch"]
snapshot_id: int = Field(alias="snapshot-id")
@@ -276,27 +276,27 @@ class SetSnapshotRefUpdate(TableUpdate):
class RemoveSnapshotsUpdate(TableUpdate):
- action = TableUpdateAction.remove_snapshots
+ action: TableUpdateAction = TableUpdateAction.remove_snapshots
snapshot_ids: List[int] = Field(alias="snapshot-ids")
class RemoveSnapshotRefUpdate(TableUpdate):
- action = TableUpdateAction.remove_snapshot_ref
+ action: TableUpdateAction = TableUpdateAction.remove_snapshot_ref
ref_name: str = Field(alias="ref-name")
class SetLocationUpdate(TableUpdate):
- action = TableUpdateAction.set_location
+ action: TableUpdateAction = TableUpdateAction.set_location
location: str
class SetPropertiesUpdate(TableUpdate):
- action = TableUpdateAction.set_properties
+ action: TableUpdateAction = TableUpdateAction.set_properties
updates: Dict[str, str]
class RemovePropertiesUpdate(TableUpdate):
- action = TableUpdateAction.remove_properties
+ action: TableUpdateAction = TableUpdateAction.remove_properties
removals: List[str]
diff --git a/python/pyiceberg/table/metadata.py
b/python/pyiceberg/table/metadata.py
index f081c75f90..d15ec3a64d 100644
--- a/python/pyiceberg/table/metadata.py
+++ b/python/pyiceberg/table/metadata.py
@@ -148,7 +148,7 @@ class TableMetadataCommonFields(IcebergBaseModel):
default_spec_id: int = Field(alias="default-spec-id",
default=INITIAL_SPEC_ID)
"""ID of the “current” spec that writers should use by default."""
- last_partition_id: Optional[int] = Field(alias="last-partition-id")
+ last_partition_id: Optional[int] = Field(alias="last-partition-id",
default=None)
"""An integer; the highest assigned partition field ID across all
partition specs for the table. This is used to ensure partition fields
are always assigned an unused ID when evolving specs."""
diff --git a/python/pyiceberg/table/snapshots.py
b/python/pyiceberg/table/snapshots.py
index e21a7ece64..b3d90eebb7 100644
--- a/python/pyiceberg/table/snapshots.py
+++ b/python/pyiceberg/table/snapshots.py
@@ -100,11 +100,13 @@ class Summary(IcebergBaseModel):
class Snapshot(IcebergBaseModel):
snapshot_id: int = Field(alias="snapshot-id")
- parent_snapshot_id: Optional[int] = Field(alias="parent-snapshot-id")
+ parent_snapshot_id: Optional[int] = Field(alias="parent-snapshot-id",
default=None)
sequence_number: Optional[int] = Field(alias="sequence-number",
default=None)
timestamp_ms: int = Field(alias="timestamp-ms")
- manifest_list: Optional[str] = Field(alias="manifest-list",
description="Location of the snapshot's manifest list file")
- summary: Optional[Summary] = Field()
+ manifest_list: Optional[str] = Field(
+ alias="manifest-list", description="Location of the snapshot's
manifest list file", default=None
+ )
+ summary: Optional[Summary] = Field(default=None)
schema_id: Optional[int] = Field(alias="schema-id", default=None)
def __str__(self) -> str:
@@ -128,5 +130,5 @@ class MetadataLogEntry(IcebergBaseModel):
class SnapshotLogEntry(IcebergBaseModel):
- snapshot_id: str = Field(alias="snapshot-id")
+ snapshot_id: int = Field(alias="snapshot-id")
timestamp_ms: int = Field(alias="timestamp-ms")
diff --git a/python/tests/catalog/test_hive.py
b/python/tests/catalog/test_hive.py
index 23bc0208b6..f353f795df 100644
--- a/python/tests/catalog/test_hive.py
+++ b/python/tests/catalog/test_hive.py
@@ -351,8 +351,8 @@ def test_load_table(hive_table: HiveTable) -> None:
),
],
snapshot_log=[
- SnapshotLogEntry(snapshot_id="3051729675574597004",
timestamp_ms=1515100955770),
- SnapshotLogEntry(snapshot_id="3055729675574597004",
timestamp_ms=1555100955770),
+ SnapshotLogEntry(snapshot_id=3051729675574597004,
timestamp_ms=1515100955770),
+ SnapshotLogEntry(snapshot_id=3055729675574597004,
timestamp_ms=1555100955770),
],
metadata_log=[MetadataLogEntry(metadata_file="s3://bucket/.../v1.json",
timestamp_ms=1515100)],
sort_orders=[
diff --git a/python/tests/table/test_init.py b/python/tests/table/test_init.py
index 8e42cc6cf8..87aa0d3815 100644
--- a/python/tests/table/test_init.py
+++ b/python/tests/table/test_init.py
@@ -184,8 +184,8 @@ def test_snapshot_by_name_does_not_exist(table: Table) ->
None:
def test_history(table: Table) -> None:
assert table.history() == [
- SnapshotLogEntry(snapshot_id="3051729675574597004",
timestamp_ms=1515100955770),
- SnapshotLogEntry(snapshot_id="3055729675574597004",
timestamp_ms=1555100955770),
+ SnapshotLogEntry(snapshot_id=3051729675574597004,
timestamp_ms=1515100955770),
+ SnapshotLogEntry(snapshot_id=3055729675574597004,
timestamp_ms=1555100955770),
]
diff --git a/python/tests/table/test_metadata.py
b/python/tests/table/test_metadata.py
index 8c464c0e5a..63ef0d07ee 100644
--- a/python/tests/table/test_metadata.py
+++ b/python/tests/table/test_metadata.py
@@ -187,7 +187,7 @@ def test_serialize_v1(example_table_metadata_v1: Dict[str,
Any]) -> None:
def test_serialize_v2(example_table_metadata_v2: Dict[str, Any]) -> None:
table_metadata = TableMetadataV2(**example_table_metadata_v2).json()
- expected = """{"location": "s3://bucket/test/location", "table-uuid":
"9c12d441-03fe-4693-9a96-a0705ddf69c1", "last-updated-ms": 1602638573590,
"last-column-id": 3, "schemas": [{"type": "struct", "fields": [{"id": 1,
"name": "x", "type": "long", "required": true}], "schema-id": 0,
"identifier-field-ids": []}, {"type": "struct", "fields": [{"id": 1, "name":
"x", "type": "long", "required": true}, {"id": 2, "name": "y", "type": "long",
"required": true, "doc": "comment"}, {"id": 3, "na [...]
+ expected = """{"location": "s3://bucket/test/location", "table-uuid":
"9c12d441-03fe-4693-9a96-a0705ddf69c1", "last-updated-ms": 1602638573590,
"last-column-id": 3, "schemas": [{"type": "struct", "fields": [{"id": 1,
"name": "x", "type": "long", "required": true}], "schema-id": 0,
"identifier-field-ids": []}, {"type": "struct", "fields": [{"id": 1, "name":
"x", "type": "long", "required": true}, {"id": 2, "name": "y", "type": "long",
"required": true, "doc": "comment"}, {"id": 3, "na [...]
assert table_metadata == expected