diff --git a/pyiceberg/view/metadata.py b/pyiceberg/view/metadata.py index 785dfd7852..33766040e3 100644 --- a/pyiceberg/view/metadata.py +++ b/pyiceberg/view/metadata.py @@ -16,6 +16,7 @@ # under the License. from __future__ import annotations +import time from typing import Literal from pydantic import Field, RootModel, field_validator @@ -44,13 +45,13 @@ class ViewRepresentation(IcebergBaseModel, RootModel): class ViewVersion(IcebergBaseModel): """A version of the view definition.""" - version_id: int = Field(alias="version-id") + version_id: int = Field(alias="version-id", default=1) """ID for the version""" schema_id: int = Field(alias="schema-id") """ID of the schema for the view version""" - timestamp_ms: int = Field(alias="timestamp-ms") + timestamp_ms: int = Field(alias="timestamp-ms", default_factory=lambda: int(time.time() * 1000)) """Timestamp when the version was created (ms from epoch)""" - summary: dict[str, str] = Field() + summary: dict[str, str] = Field(default_factory=dict) """A string to string map of summary metadata about the version""" representations: list[ViewRepresentation] = Field() """A list of representations for the view definition""" diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py index 1eb9f26a56..691e163744 100644 --- a/tests/catalog/test_rest.py +++ b/tests/catalog/test_rest.py @@ -1746,8 +1746,6 @@ def test_create_view_200(rest_mock: Mocker, table_schema_simple: Schema, example identifier=("fokko", "fokko2"), schema=table_schema_simple, view_version=ViewVersion( - version_id=1, - timestamp_ms=12345, schema_id=1, summary={"engine-name": "spark", "engineVersion": "3.3"}, representations=[ @@ -1791,8 +1789,6 @@ def test_create_view_409( identifier=("fokko", "fokko2"), schema=table_schema_simple, view_version=ViewVersion( - version_id=1, - timestamp_ms=12345, schema_id=1, summary={"engine-name": "spark", "engineVersion": "3.3"}, representations=[], diff --git a/tests/integration/test_writes/test_writes.py b/tests/integration/test_writes/test_writes.py index 609c1863bc..2a0c50a921 100644 --- a/tests/integration/test_writes/test_writes.py +++ b/tests/integration/test_writes/test_writes.py @@ -1769,10 +1769,7 @@ def test_create_view( identifier = "default.some_view" schema = pa.schema([pa.field("some_col", pa.int32())]) view_version = ViewVersion( - version_id=1, schema_id=1, - timestamp_ms=int(time.time() * 1000), - summary={}, representations=[ SQLViewRepresentation( type="sql",