|
19 | 19 |
|
20 | 20 | #include "iceberg/json_internal.h" |
21 | 21 |
|
| 22 | +#include <cstdint> |
22 | 23 | #include <format> |
23 | 24 | #include <regex> |
24 | 25 | #include <unordered_set> |
@@ -82,6 +83,8 @@ constexpr std::string_view kMinSnapshotsToKeep = "min-snapshots-to-keep"; |
82 | 83 | constexpr std::string_view kMaxSnapshotAgeMs = "max-snapshot-age-ms"; |
83 | 84 | constexpr std::string_view kMaxRefAgeMs = "max-ref-age-ms"; |
84 | 85 |
|
| 86 | +constexpr int64_t kInitialSequenceNumber = 0; |
| 87 | + |
85 | 88 | const std::unordered_set<std::string_view> kValidSnapshotSummaryFields = { |
86 | 89 | SnapshotSummaryFields::kOperation, |
87 | 90 | SnapshotSummaryFields::kAddedDataFiles, |
@@ -324,7 +327,9 @@ nlohmann::json ToJson(const Snapshot& snapshot) { |
324 | 327 | nlohmann::json json; |
325 | 328 | json[kSnapshotId] = snapshot.snapshot_id; |
326 | 329 | SetOptionalField(json, kParentSnapshotId, snapshot.parent_snapshot_id); |
327 | | - json[kSequenceNumber] = snapshot.sequence_number; |
| 330 | + if (snapshot.sequence_number > kInitialSequenceNumber) { |
| 331 | + json[kSequenceNumber] = snapshot.sequence_number; |
| 332 | + } |
328 | 333 | json[kTimestampMs] = snapshot.timestamp_ms; |
329 | 334 | json[kManifestList] = snapshot.manifest_list; |
330 | 335 | // If there is an operation, write the summary map |
@@ -552,7 +557,7 @@ Result<std::unique_ptr<SnapshotRef>> SnapshotRefFromJson(const nlohmann::json& j |
552 | 557 | Result<std::unique_ptr<Snapshot>> SnapshotFromJson(const nlohmann::json& json) { |
553 | 558 | ICEBERG_ASSIGN_OR_RAISE(auto snapshot_id, GetJsonValue<int64_t>(json, kSnapshotId)); |
554 | 559 | ICEBERG_ASSIGN_OR_RAISE(auto sequence_number, |
555 | | - GetJsonValue<int64_t>(json, kSequenceNumber)); |
| 560 | + GetJsonValueOptional<int64_t>(json, kSequenceNumber)); |
556 | 561 | ICEBERG_ASSIGN_OR_RAISE(auto timestamp_ms, GetJsonValue<int64_t>(json, kTimestampMs)); |
557 | 562 | ICEBERG_ASSIGN_OR_RAISE(auto manifest_list, |
558 | 563 | GetJsonValue<std::string>(json, kManifestList)); |
@@ -591,9 +596,10 @@ Result<std::unique_ptr<Snapshot>> SnapshotFromJson(const nlohmann::json& json) { |
591 | 596 |
|
592 | 597 | ICEBERG_ASSIGN_OR_RAISE(auto schema_id, GetJsonValueOptional<int32_t>(json, kSchemaId)); |
593 | 598 |
|
594 | | - return std::make_unique<Snapshot>(snapshot_id, parent_snapshot_id, sequence_number, |
595 | | - timestamp_ms, manifest_list, std::move(summary), |
596 | | - schema_id); |
| 599 | + return std::make_unique<Snapshot>( |
| 600 | + snapshot_id, parent_snapshot_id, |
| 601 | + sequence_number.has_value() ? *sequence_number : kInitialSequenceNumber, |
| 602 | + timestamp_ms, manifest_list, std::move(summary), schema_id); |
597 | 603 | } |
598 | 604 |
|
599 | 605 | } // namespace iceberg |
0 commit comments