zhjwpku commented on code in PR #74:
URL: https://github.com/apache/iceberg-cpp/pull/74#discussion_r2043592188


##########
src/iceberg/json_internal.cc:
##########
@@ -231,6 +296,53 @@ nlohmann::json SchemaToJson(const Schema& schema) {
   return json;
 }
 
+nlohmann::json SnapshotRefToJson(const SnapshotRef& ref) {
+  nlohmann::json json;
+  json[kSnapshotId] = ref.snapshot_id;
+  json[kType] = SnapshotRefTypeToString(ref.type());
+  if (ref.type() == SnapshotRefType::kBranch) {
+    const auto& branch = std::get<SnapshotRef::Branch>(ref.retention);
+    if (branch.min_snapshots_to_keep.has_value()) {
+      json[kMinSnapshotsToKeep] = *branch.min_snapshots_to_keep;
+    }
+    if (branch.max_snapshot_age_ms.has_value()) {
+      json[kMaxSnapshotAgeMs] = *branch.max_snapshot_age_ms;
+    }
+    if (branch.max_ref_age_ms.has_value()) {
+      json[kMaxRefAgeMs] = *branch.max_ref_age_ms;
+    }
+  } else if (ref.type() == SnapshotRefType::kTag) {
+    const auto& tag = std::get<SnapshotRef::Tag>(ref.retention);
+    if (tag.max_ref_age_ms.has_value()) {
+      json[kMaxRefAgeMs] = *tag.max_ref_age_ms;
+    }
+  }
+  return json;
+}
+
+nlohmann::json SnapshotToJson(const Snapshot& snapshot) {
+  nlohmann::json json;
+  json[kSnapshotId] = snapshot.snapshot_id;
+  if (snapshot.parent_snapshot_id.has_value()) {
+    json[kParentSnapshotId] = *snapshot.parent_snapshot_id;
+  }
+  json[kSequenceNumber] = snapshot.sequence_number;
+  json[kTimestampMs] = snapshot.timestamp_ms;

Review Comment:
   I notice that there is a `using TimePointMs` in table_metadata.h, do you 
mind I do this in a separate PR, I think we should put this in a common header 
files, but I haven't think too hard about the header name.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to