Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/iceberg/json_serde.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ constexpr std::string_view kSortOrderId = "sort-order-id";
constexpr std::string_view kSnapshot = "snapshot";
constexpr std::string_view kSnapshotIds = "snapshot-ids";
constexpr std::string_view kRefName = "ref-name";
constexpr std::string_view kRef = "ref";
constexpr std::string_view kUpdates = "updates";
constexpr std::string_view kRemovals = "removals";

Expand Down Expand Up @@ -1505,7 +1506,8 @@ nlohmann::json ToJson(const TableRequirement& requirement) {
const auto& r =
internal::checked_cast<const table::AssertRefSnapshotID&>(requirement);
json[kType] = kRequirementAssertRefSnapshotID;
json[kRefName] = r.ref_name();
// REST spec names this field "ref", not "ref-name".
json[kRef] = r.ref_name();
if (r.snapshot_id().has_value()) {
json[kSnapshotId] = r.snapshot_id().value();
} else {
Expand Down Expand Up @@ -1702,7 +1704,7 @@ Result<std::unique_ptr<TableRequirement>> TableRequirementFromJson(
return std::make_unique<table::AssertUUID>(std::move(uuid));
}
if (type == kRequirementAssertRefSnapshotID) {
ICEBERG_ASSIGN_OR_RAISE(auto ref_name, GetJsonValue<std::string>(json, kRefName));
ICEBERG_ASSIGN_OR_RAISE(auto ref_name, GetJsonValue<std::string>(json, kRef));
ICEBERG_ASSIGN_OR_RAISE(auto snapshot_id_opt,
GetJsonValueOptional<int64_t>(json, kSnapshotId));
return std::make_unique<table::AssertRefSnapshotID>(std::move(ref_name),
Expand Down
12 changes: 10 additions & 2 deletions src/iceberg/test/json_serde_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ TEST(TableRequirementJsonTest, TableRequirementAssertUUID) {
TEST(TableRequirementJsonTest, TableRequirementAssertRefSnapshotID) {
table::AssertRefSnapshotID req("main", 123456789);
nlohmann::json expected =
R"({"type":"assert-ref-snapshot-id","ref-name":"main","snapshot-id":123456789})"_json;
R"({"type":"assert-ref-snapshot-id","ref":"main","snapshot-id":123456789})"_json;

EXPECT_EQ(ToJson(req), expected);
auto parsed = TableRequirementFromJson(expected);
Expand All @@ -693,7 +693,7 @@ TEST(TableRequirementJsonTest, TableRequirementAssertRefSnapshotID) {
TEST(TableRequirementJsonTest, TableRequirementAssertRefSnapshotIDWithNull) {
table::AssertRefSnapshotID req("main", std::nullopt);
nlohmann::json expected =
R"({"type":"assert-ref-snapshot-id","ref-name":"main","snapshot-id":null})"_json;
R"({"type":"assert-ref-snapshot-id","ref":"main","snapshot-id":null})"_json;

EXPECT_EQ(ToJson(req), expected);
auto parsed = TableRequirementFromJson(expected);
Expand All @@ -702,6 +702,14 @@ TEST(TableRequirementJsonTest, TableRequirementAssertRefSnapshotIDWithNull) {
req);
}

TEST(TableRequirementJsonTest, TableRequirementAssertRefSnapshotIDRejectsRefName) {
nlohmann::json legacy =
R"({"type":"assert-ref-snapshot-id","ref-name":"main","snapshot-id":123456789})"_json;
auto result = TableRequirementFromJson(legacy);
EXPECT_THAT(result, IsError(ErrorKind::kJsonParseError));
EXPECT_THAT(result, HasErrorMessage("Missing 'ref'"));
}

TEST(TableRequirementJsonTest, TableRequirementAssertLastAssignedFieldId) {
table::AssertLastAssignedFieldId req(100);
nlohmann::json expected =
Expand Down
Loading