-
Notifications
You must be signed in to change notification settings - Fork 92
feat: snapshot serde #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3ec142a
ef171a4
8847ca8
296d04f
e3fd584
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| #include "iceberg/json_internal.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <format> | ||
| #include <regex> | ||
| #include <unordered_set> | ||
|
|
@@ -82,6 +83,8 @@ constexpr std::string_view kMinSnapshotsToKeep = "min-snapshots-to-keep"; | |
| constexpr std::string_view kMaxSnapshotAgeMs = "max-snapshot-age-ms"; | ||
| constexpr std::string_view kMaxRefAgeMs = "max-ref-age-ms"; | ||
|
|
||
| constexpr int64_t kInitialSequenceNumber = 0; | ||
|
|
||
| const std::unordered_set<std::string_view> kValidSnapshotSummaryFields = { | ||
| SnapshotSummaryFields::kOperation, | ||
| SnapshotSummaryFields::kAddedDataFiles, | ||
|
|
@@ -324,7 +327,9 @@ nlohmann::json ToJson(const Snapshot& snapshot) { | |
| nlohmann::json json; | ||
| json[kSnapshotId] = snapshot.snapshot_id; | ||
| SetOptionalField(json, kParentSnapshotId, snapshot.parent_snapshot_id); | ||
| json[kSequenceNumber] = snapshot.sequence_number; | ||
| if (snapshot.sequence_number > kInitialSequenceNumber) { | ||
| json[kSequenceNumber] = snapshot.sequence_number; | ||
| } | ||
| json[kTimestampMs] = snapshot.timestamp_ms; | ||
| json[kManifestList] = snapshot.manifest_list; | ||
| // If there is an operation, write the summary map | ||
|
|
@@ -552,7 +557,7 @@ Result<std::unique_ptr<SnapshotRef>> SnapshotRefFromJson(const nlohmann::json& j | |
| Result<std::unique_ptr<Snapshot>> SnapshotFromJson(const nlohmann::json& json) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the spec,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're correct!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds like we need to set
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, please take a look. |
||
| ICEBERG_ASSIGN_OR_RAISE(auto snapshot_id, GetJsonValue<int64_t>(json, kSnapshotId)); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto sequence_number, | ||
zhjwpku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| GetJsonValue<int64_t>(json, kSequenceNumber)); | ||
| GetJsonValueOptional<int64_t>(json, kSequenceNumber)); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto timestamp_ms, GetJsonValue<int64_t>(json, kTimestampMs)); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto manifest_list, | ||
| GetJsonValue<std::string>(json, kManifestList)); | ||
|
|
@@ -591,9 +596,10 @@ Result<std::unique_ptr<Snapshot>> SnapshotFromJson(const nlohmann::json& json) { | |
|
|
||
| ICEBERG_ASSIGN_OR_RAISE(auto schema_id, GetJsonValueOptional<int32_t>(json, kSchemaId)); | ||
|
|
||
| return std::make_unique<Snapshot>(snapshot_id, parent_snapshot_id, sequence_number, | ||
| timestamp_ms, manifest_list, std::move(summary), | ||
| schema_id); | ||
| return std::make_unique<Snapshot>( | ||
| snapshot_id, parent_snapshot_id, | ||
| sequence_number.has_value() ? *sequence_number : kInitialSequenceNumber, | ||
| timestamp_ms, manifest_list, std::move(summary), schema_id); | ||
| } | ||
|
|
||
| } // namespace iceberg | ||
Uh oh!
There was an error while loading. Please reload this page.