Skip to content

Commit ec1413d

Browse files
authored
Add defaults to ViewVersion fields (#3458)
# Rationale for this change Allow users to create a view with fewer parameters. We can set an environment context (`engine-name` and `engine-version`) in `summary` field by default once #3441 is merged. ## Are these changes tested? Yes ## Are there any user-facing changes? No <!-- In the case of user-facing changes, please add the changelog label. -->
1 parent b231705 commit ec1413d

3 files changed

Lines changed: 4 additions & 10 deletions

File tree

pyiceberg/view/metadata.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717
from __future__ import annotations
1818

19+
import time
1920
from typing import Literal
2021

2122
from pydantic import Field, RootModel, field_validator
@@ -44,13 +45,13 @@ class ViewRepresentation(IcebergBaseModel, RootModel):
4445
class ViewVersion(IcebergBaseModel):
4546
"""A version of the view definition."""
4647

47-
version_id: int = Field(alias="version-id")
48+
version_id: int = Field(alias="version-id", default=1)
4849
"""ID for the version"""
4950
schema_id: int = Field(alias="schema-id")
5051
"""ID of the schema for the view version"""
51-
timestamp_ms: int = Field(alias="timestamp-ms")
52+
timestamp_ms: int = Field(alias="timestamp-ms", default_factory=lambda: int(time.time() * 1000))
5253
"""Timestamp when the version was created (ms from epoch)"""
53-
summary: dict[str, str] = Field()
54+
summary: dict[str, str] = Field(default_factory=dict)
5455
"""A string to string map of summary metadata about the version"""
5556
representations: list[ViewRepresentation] = Field()
5657
"""A list of representations for the view definition"""

tests/catalog/test_rest.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,8 +1746,6 @@ def test_create_view_200(rest_mock: Mocker, table_schema_simple: Schema, example
17461746
identifier=("fokko", "fokko2"),
17471747
schema=table_schema_simple,
17481748
view_version=ViewVersion(
1749-
version_id=1,
1750-
timestamp_ms=12345,
17511749
schema_id=1,
17521750
summary={"engine-name": "spark", "engineVersion": "3.3"},
17531751
representations=[
@@ -1791,8 +1789,6 @@ def test_create_view_409(
17911789
identifier=("fokko", "fokko2"),
17921790
schema=table_schema_simple,
17931791
view_version=ViewVersion(
1794-
version_id=1,
1795-
timestamp_ms=12345,
17961792
schema_id=1,
17971793
summary={"engine-name": "spark", "engineVersion": "3.3"},
17981794
representations=[],

tests/integration/test_writes/test_writes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,10 +1769,7 @@ def test_create_view(
17691769
identifier = "default.some_view"
17701770
schema = pa.schema([pa.field("some_col", pa.int32())])
17711771
view_version = ViewVersion(
1772-
version_id=1,
17731772
schema_id=1,
1774-
timestamp_ms=int(time.time() * 1000),
1775-
summary={},
17761773
representations=[
17771774
SQLViewRepresentation(
17781775
type="sql",

0 commit comments

Comments
 (0)