Fokko commented on code in PR #5011: URL: https://github.com/apache/iceberg/pull/5011#discussion_r905462916
########## python/src/iceberg/table/metadata.py: ########## @@ -0,0 +1,259 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from enum import Enum +from typing import ( + Any, + Dict, + List, + Literal, + Optional, + Union, +) +from uuid import UUID + +from pydantic import Field, root_validator + +from iceberg.schema import Schema +from iceberg.utils.iceberg_base_model import IcebergBaseModel + +_INITIAL_SEQUENCE_NUMBER = 0 +INITIAL_SPEC_ID = 0 +DEFAULT_SCHEMA_ID = 0 + + +class SnapshotRefType(str, Enum): + branch = "branch" + tag = "tag" + + +class SnapshotRef(IcebergBaseModel): + snapshot_id: int = Field(alias="snapshot-id") + snapshot_ref_type: SnapshotRefType = Field(alias="type") + min_snapshots_to_keep: int = Field(alias="min-snapshots-to-keep") + max_snapshot_age_ms: int = Field(alias="max-snapshot-age-ms") + max_ref_age_ms: int = Field(alias="max-ref-age-ms") + + +class TableMetadataCommonFields(IcebergBaseModel): Review Comment: Since refs are added as optional in V2:  I've added them as a property of the V2. Since they are optional, I set the `default_factory` to `dict`: ```python class TableMetadataV2(TableMetadataCommonFields, IcebergBaseModel): ... refs: Dict[str, SnapshotRef] = Field(default_factory=dict) """A map of snapshot references. The map keys are the unique snapshot reference names in the table, and the map values are snapshot reference objects. There is always a main branch reference pointing to the current-snapshot-id even if the refs map is null.""" ``` If it isn't supplied, an empty `dict` will be set. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
