TheR1sing3un commented on code in PR #8319:
URL: https://github.com/apache/paimon/pull/8319#discussion_r3460786244
##########
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:
fixed
##########
paimon-python/pypaimon/catalog/filesystem_catalog.py:
##########
@@ -453,16 +451,24 @@ def get_tag(
tag = table.tag_manager().get(tag_name)
if tag is None:
raise TagNotExistException(tag_name)
- # tag_create_time / tag_time_retained are not tracked on the
- # filesystem side yet — the Python Tag dataclass inherits only
- # Snapshot fields. Returning ``None`` for both keeps the response
- # shape compatible with the Java contract while making the gap
- # visible to callers.
+ # Surface tag_create_time as epoch millis and tag_time_retained as an
+ # ISO-8601 duration string (types match the Java REST GetTagResponse
+ # Long / String). The millis treat the timezone-less create-time as UTC
+ # (consistent with the ``$tags`` system table); note Java's REST server
+ # converts using the system default zone, so the numeric value can
+ # differ on non-UTC hosts. Both are None for tags created without a
+ # retention (plain-snapshot tag files).
return GetTagResponse(
tag_name=tag_name,
snapshot=tag.trim_to_snapshot(),
- tag_create_time=None,
- tag_time_retained=None,
+ tag_create_time=(
+ None if tag.tag_create_time is None
+ else local_datetime_to_millis(tag.tag_create_time)
Review Comment:
fixed
--
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]