Skip to content

Commit e3fd584

Browse files
committed
fix: when summary with no operation field, set operation to overwrite
1 parent 296d04f commit e3fd584

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/iceberg/json_internal.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ Result<std::unique_ptr<Snapshot>> SnapshotFromJson(const nlohmann::json& json) {
592592
}
593593
summary[key] = value.get<std::string>();
594594
}
595+
// If summary is available but operation is missing, set operation to overwrite.
596+
if (!summary.contains(SnapshotSummaryFields::kOperation)) {
597+
summary[SnapshotSummaryFields::kOperation] = DataOperation::kOverwrite;
598+
}
595599
}
596600

597601
ICEBERG_ASSIGN_OR_RAISE(auto schema_id, GetJsonValueOptional<int32_t>(json, kSchemaId));

test/json_internal_test.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ TEST(JsonInternalTest, Snapshot) {
219219
}
220220

221221
TEST(JsonInternalTest, SnapshotFromJsonWithInvalidSummary) {
222-
nlohmann::json invalid_json_snapshot =
222+
nlohmann::json invalid_json =
223223
R"({"snapshot-id":1234567890,
224224
"parent-snapshot-id":9876543210,
225225
"sequence-number":99,
@@ -229,12 +229,31 @@ TEST(JsonInternalTest, SnapshotFromJsonWithInvalidSummary) {
229229
"invalid-field":"value"
230230
},
231231
"schema-id":42})"_json;
232+
// malformed summary field
232233

233-
auto result = SnapshotFromJson(invalid_json_snapshot);
234+
auto result = SnapshotFromJson(invalid_json);
234235
ASSERT_FALSE(result.has_value());
235236

236237
EXPECT_THAT(result, IsError(ErrorKind::kJsonParseError));
237238
EXPECT_THAT(result, HasErrorMessage("Invalid snapshot summary field"));
238239
}
239240

241+
TEST(JsonInternalTest, SnapshotFromJsonSummaryWithNoOperation) {
242+
nlohmann::json snapshot_json =
243+
R"({"snapshot-id":1234567890,
244+
"parent-snapshot-id":9876543210,
245+
"sequence-number":99,
246+
"timestamp-ms":1234567890123,
247+
"manifest-list":"/path/to/manifest_list",
248+
"summary":{
249+
"added-data-files":"50"
250+
},
251+
"schema-id":42})"_json;
252+
253+
auto result = SnapshotFromJson(snapshot_json);
254+
ASSERT_TRUE(result.has_value());
255+
256+
ASSERT_EQ(result.value()->operation(), DataOperation::kOverwrite);
257+
}
258+
240259
} // namespace iceberg

0 commit comments

Comments
 (0)