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


##########
src/iceberg/json_internal.cc:
##########
@@ -419,4 +520,75 @@ Result<std::unique_ptr<PartitionSpec>> 
PartitionSpecFromJson(
   return std::make_unique<PartitionSpec>(schema, spec_id, 
std::move(partition_fields));
 }
 
+Result<std::unique_ptr<SnapshotRef>> SnapshotRefFromJson(const nlohmann::json& 
json) {
+  ICEBERG_ASSIGN_OR_RAISE(auto snapshot_id, GetJsonValue<int64_t>(json, 
kSnapshotId));
+  ICEBERG_ASSIGN_OR_RAISE(
+      auto type,
+      GetJsonValue<std::string>(json, 
kType).and_then(SnapshotRefTypeFromString));
+  if (type == SnapshotRefType::kBranch) {
+    ICEBERG_ASSIGN_OR_RAISE(auto min_snapshots_to_keep,
+                            GetJsonValueOptional<int32_t>(json, 
kMinSnapshotsToKeep));
+    ICEBERG_ASSIGN_OR_RAISE(auto max_snapshot_age_ms,
+                            GetJsonValueOptional<int64_t>(json, 
kMaxSnapshotAgeMs));
+    ICEBERG_ASSIGN_OR_RAISE(auto max_ref_age_ms,
+                            GetJsonValueOptional<int64_t>(json, kMaxRefAgeMs));
+
+    return std::make_unique<SnapshotRef>(
+        snapshot_id, SnapshotRef::Branch{.min_snapshots_to_keep = 
min_snapshots_to_keep,
+                                         .max_snapshot_age_ms = 
max_snapshot_age_ms,
+                                         .max_ref_age_ms = max_ref_age_ms});
+  } else {
+    ICEBERG_ASSIGN_OR_RAISE(auto max_ref_age_ms,
+                            GetJsonValueOptional<int64_t>(json, kMaxRefAgeMs));
+
+    return std::make_unique<SnapshotRef>(
+        snapshot_id, SnapshotRef::Tag{.max_ref_age_ms = max_ref_age_ms});
+  }
+}
+
+Result<std::unique_ptr<Snapshot>> SnapshotFromJson(const nlohmann::json& json) 
{

Review Comment:
   I think we need to be consistent with the Java impl: 
https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/SnapshotParser.java.
 Specifically, we need to deal with cases where sequence number or summary is 
missing.
   
   @Fokko Will it actually happen that a snapshot does not have `summary` (and 
thus `operation` is also missing)?



-- 
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