JingsongLi commented on code in PR #8319: URL: https://github.com/apache/paimon/pull/8319#discussion_r3460346455
########## paimon-python/pypaimon/tag/tag.py: ########## @@ -15,10 +15,76 @@ # specific language governing permissions and limitations # under the License. +from dataclasses import dataclass +from datetime import datetime, timedelta +from typing import Optional + +from pypaimon.common.json_util import json_field_with_codec +from pypaimon.common.time_utils import ( + duration_to_json_seconds, + json_array_to_local_datetime, + json_seconds_to_duration, + local_datetime_to_json_array, +) from pypaimon.snapshot.snapshot import Snapshot +@dataclass class Tag(Snapshot): + """A Snapshot with optional ``tagCreateTime`` and ``tagTimeRetained`` (TTL). + + Both fields mirror Java ``org.apache.paimon.tag.Tag`` and are serialized in + the same on-disk JSON shape (LocalDateTime as a ``[y, mo, d, h, mi, s, ns]`` + array, Duration as decimal seconds), so tag files round-trip across the Java + and Python SDKs. They are ``None`` for tags created without a retention. + """ + + tag_create_time: Optional[datetime] = json_field_with_codec( + "tagCreateTime", + encoder=local_datetime_to_json_array, + decoder=json_array_to_local_datetime, + ) + tag_time_retained: Optional[timedelta] = json_field_with_codec( + "tagTimeRetained", + encoder=duration_to_json_seconds, + decoder=json_seconds_to_duration, + ) + + @staticmethod + def from_snapshot_and_tag_ttl( + snapshot: Snapshot, + tag_time_retained: Optional[timedelta], + tag_create_time: datetime, + ) -> "Tag": + """Build a Tag from a Snapshot plus tag-specific TTL metadata. + + Mirrors Java ``Tag.fromSnapshotAndTagTtl``. + """ + return Tag( + version=snapshot.version, + id=snapshot.id, + schema_id=snapshot.schema_id, + base_manifest_list=snapshot.base_manifest_list, + delta_manifest_list=snapshot.delta_manifest_list, + total_record_count=snapshot.total_record_count, + delta_record_count=snapshot.delta_record_count, + commit_user=snapshot.commit_user, + commit_identifier=snapshot.commit_identifier, + commit_kind=snapshot.commit_kind, + time_millis=snapshot.time_millis, + base_manifest_list_size=snapshot.base_manifest_list_size, Review Comment: This field is preserved when building the TTL `Tag`, but `trim_to_snapshot()` below still drops it again (along with `delta_manifest_list_size`, `changelog_manifest_list_size`, and `properties`). Since `FileSystemCatalog.get_tag()` returns `tag.trim_to_snapshot()`, the REST/catalog response loses those Snapshot fields for TTL tags, unlike Java `Tag.trimToSnapshot()`. Please copy all optional Snapshot fields in `trim_to_snapshot()` too. -- 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]
