Fokko commented on code in PR #74: URL: https://github.com/apache/iceberg-cpp/pull/74#discussion_r2044843490
########## 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: You're correct! - For V1 the summary is optional. - For V2/V3 the summary is required, and also the operation. Some writers produced some malformed metadata in the past. Instead of throwing an exception, we would it is an overwrite operation, since that's the most generic one. -- 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