Skip to content

Commit 17284f8

Browse files
committed
fix review
1 parent 2f0b716 commit 17284f8

File tree

12 files changed

+968
-673
lines changed

12 files changed

+968
-673
lines changed

src/iceberg/catalog/rest/json_internal.cc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ constexpr std::string_view kType = "type";
7171
constexpr std::string_view kCode = "code";
7272
constexpr std::string_view kStack = "stack";
7373
constexpr std::string_view kError = "error";
74-
75-
// CommitTableRequest field constants
7674
constexpr std::string_view kIdentifier = "identifier";
7775
constexpr std::string_view kRequirements = "requirements";
7876

@@ -400,18 +398,18 @@ Result<CreateTableRequest> CreateTableRequestFromJson(const nlohmann::json& json
400398
nlohmann::json ToJson(const CommitTableRequest& request) {
401399
nlohmann::json json;
402400
if (!request.identifier.name.empty()) {
403-
json[kIdentifier] = iceberg::ToJson(request.identifier);
401+
json[kIdentifier] = ToJson(request.identifier);
404402
}
405403

406404
nlohmann::json requirements_json = nlohmann::json::array();
407405
for (const auto& req : request.requirements) {
408-
requirements_json.push_back(iceberg::ToJson(*req));
406+
requirements_json.push_back(ToJson(*req));
409407
}
410408
json[kRequirements] = std::move(requirements_json);
411409

412410
nlohmann::json updates_json = nlohmann::json::array();
413411
for (const auto& update : request.updates) {
414-
updates_json.push_back(iceberg::ToJson(*update));
412+
updates_json.push_back(ToJson(*update));
415413
}
416414
json[kUpdates] = std::move(updates_json);
417415

@@ -425,24 +423,39 @@ Result<CommitTableRequest> CommitTableRequestFromJson(const nlohmann::json& json
425423
GetJsonValue<nlohmann::json>(json, kIdentifier));
426424
ICEBERG_ASSIGN_OR_RAISE(request.identifier, TableIdentifierFromJson(identifier_json));
427425
}
428-
// Note: requirements and updates deserialization would be complex
429-
// and is not typically needed for the client side
426+
427+
ICEBERG_ASSIGN_OR_RAISE(auto requirements_json,
428+
GetJsonValue<nlohmann::json>(json, kRequirements));
429+
for (const auto& req_json : requirements_json) {
430+
ICEBERG_ASSIGN_OR_RAISE(auto requirement, TableRequirementFromJson(req_json));
431+
request.requirements.push_back(std::move(requirement));
432+
}
433+
434+
ICEBERG_ASSIGN_OR_RAISE(auto updates_json,
435+
GetJsonValue<nlohmann::json>(json, kUpdates));
436+
for (const auto& update_json : updates_json) {
437+
ICEBERG_ASSIGN_OR_RAISE(auto update, TableUpdateFromJson(update_json));
438+
request.updates.push_back(std::move(update));
439+
}
440+
430441
ICEBERG_RETURN_UNEXPECTED(request.Validate());
431442
return request;
432443
}
433444

434445
// CommitTableResponse serialization
435446
nlohmann::json ToJson(const CommitTableResponse& response) {
436447
nlohmann::json json;
437-
SetOptionalStringField(json, kMetadataLocation, response.metadata_location);
438-
json[kMetadata] = ToJson(*response.metadata);
448+
json[kMetadataLocation] = response.metadata_location;
449+
if (response.metadata) {
450+
json[kMetadata] = ToJson(*response.metadata);
451+
}
439452
return json;
440453
}
441454

442455
Result<CommitTableResponse> CommitTableResponseFromJson(const nlohmann::json& json) {
443456
CommitTableResponse response;
444457
ICEBERG_ASSIGN_OR_RAISE(response.metadata_location,
445-
GetJsonValueOrDefault<std::string>(json, kMetadataLocation));
458+
GetJsonValue<std::string>(json, kMetadataLocation));
446459
ICEBERG_ASSIGN_OR_RAISE(auto metadata_json,
447460
GetJsonValue<nlohmann::json>(json, kMetadata));
448461
ICEBERG_ASSIGN_OR_RAISE(response.metadata, TableMetadataFromJson(metadata_json));

src/iceberg/catalog/rest/rest_catalog.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "iceberg/schema.h"
4343
#include "iceberg/sort_order.h"
4444
#include "iceberg/table.h"
45+
#include "iceberg/table_requirement.h"
46+
#include "iceberg/table_update.h"
4547
#include "iceberg/util/macros.h"
4648

4749
namespace iceberg::rest {
@@ -175,7 +177,7 @@ Result<std::vector<Namespace>> RestCatalog::ListNamespaces(const Namespace& ns)
175177
if (list_response.next_page_token.empty()) {
176178
return result;
177179
}
178-
next_token = list_response.next_page_token;
180+
next_token = std::move(list_response.next_page_token);
179181
}
180182
return result;
181183
}
@@ -245,7 +247,7 @@ Status RestCatalog::UpdateNamespaceProperties(
245247
}
246248

247249
Result<std::vector<TableIdentifier>> RestCatalog::ListTables(const Namespace& ns) const {
248-
ICEBERG_ENDPOINT_CHECK(supported_endpoints_, Endpoint::CreateTable());
250+
ICEBERG_ENDPOINT_CHECK(supported_endpoints_, Endpoint::ListTables());
249251

250252
ICEBERG_ASSIGN_OR_RAISE(auto path, paths_->Tables(ns));
251253
std::vector<TableIdentifier> result;
@@ -265,7 +267,7 @@ Result<std::vector<TableIdentifier>> RestCatalog::ListTables(const Namespace& ns
265267
if (list_response.next_page_token.empty()) {
266268
return result;
267269
}
268-
next_token = list_response.next_page_token;
270+
next_token = std::move(list_response.next_page_token);
269271
}
270272
return result;
271273
}
@@ -304,18 +306,17 @@ Result<std::shared_ptr<Table>> RestCatalog::UpdateTable(
304306
const TableIdentifier& identifier,
305307
const std::vector<std::unique_ptr<TableRequirement>>& requirements,
306308
const std::vector<std::unique_ptr<TableUpdate>>& updates) {
307-
ICEBERG_ENDPOINT_CHECK(supported_endpoints_, Endpoint::CreateTable());
309+
ICEBERG_ENDPOINT_CHECK(supported_endpoints_, Endpoint::UpdateTable());
308310
ICEBERG_ASSIGN_OR_RAISE(auto path, paths_->Table(identifier));
309311

310-
// Build request with non-owning shared_ptr (using no-op deleter)
311312
CommitTableRequest request{.identifier = identifier};
312313
request.requirements.reserve(requirements.size());
313314
for (const auto& req : requirements) {
314-
request.requirements.emplace_back(req.get(), [](auto*) {});
315+
request.requirements.push_back(req->Clone());
315316
}
316317
request.updates.reserve(updates.size());
317318
for (const auto& update : updates) {
318-
request.updates.emplace_back(update.get(), [](auto*) {});
319+
request.updates.push_back(update->Clone());
319320
}
320321

321322
ICEBERG_ASSIGN_OR_RAISE(auto json_request, ToJsonString(ToJson(request)));
@@ -419,10 +420,9 @@ Result<std::shared_ptr<Table>> RestCatalog::RegisterTable(
419420

420421
ICEBERG_ASSIGN_OR_RAISE(auto json, FromJsonString(response.body()));
421422
ICEBERG_ASSIGN_OR_RAISE(auto load_result, LoadTableResultFromJson(json));
422-
auto non_const_catalog = std::const_pointer_cast<RestCatalog>(shared_from_this());
423-
return Table::Make(identifier, load_result.metadata,
423+
return Table::Make(identifier, std::move(load_result.metadata),
424424
std::move(load_result.metadata_location), file_io_,
425-
non_const_catalog);
425+
shared_from_this());
426426
}
427427

428428
} // namespace iceberg::rest

src/iceberg/catalog/rest/types.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "iceberg/schema.h"
2424
#include "iceberg/sort_order.h"
2525
#include "iceberg/table_metadata.h"
26+
#include "iceberg/table_requirement.h"
27+
#include "iceberg/table_update.h"
2628

2729
namespace iceberg::rest {
2830

@@ -79,8 +81,25 @@ bool CommitTableRequest::operator==(const CommitTableRequest& other) const {
7981
if (updates.size() != other.updates.size()) {
8082
return false;
8183
}
82-
// Note: Deep comparison of requirements and updates is not implemented
83-
// as they contain polymorphic types. This is primarily for testing.
84+
85+
for (size_t i = 0; i < requirements.size(); ++i) {
86+
if (!requirements[i] != !other.requirements[i]) {
87+
return false;
88+
}
89+
if (requirements[i] && !requirements[i]->Equals(*other.requirements[i])) {
90+
return false;
91+
}
92+
}
93+
94+
for (size_t i = 0; i < updates.size(); ++i) {
95+
if (!updates[i] != !other.updates[i]) {
96+
return false;
97+
}
98+
if (updates[i] && !updates[i]->Equals(*other.updates[i])) {
99+
return false;
100+
}
101+
}
102+
84103
return true;
85104
}
86105

src/iceberg/catalog/rest/types.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include "iceberg/result.h"
3030
#include "iceberg/schema.h"
3131
#include "iceberg/table_identifier.h"
32-
#include "iceberg/table_requirement.h"
33-
#include "iceberg/table_update.h"
3432
#include "iceberg/type_fwd.h"
3533
#include "iceberg/util/macros.h"
3634

@@ -61,11 +59,12 @@ struct ICEBERG_REST_EXPORT ErrorResponse {
6159
/// \brief Validates the ErrorResponse.
6260
Status Validate() const {
6361
if (message.empty() || type.empty()) {
64-
return Invalid("Invalid error response: missing required fields");
62+
return ValidationFailed("Invalid error response: missing required fields");
6563
}
6664

6765
if (code < 400 || code > 600) {
68-
return Invalid("Invalid error response: code {} is out of range [400, 600]", code);
66+
return ValidationFailed(
67+
"Invalid error response: code {} is out of range [400, 600]", code);
6968
}
7069

7170
// stack is optional, no validation needed
@@ -95,7 +94,7 @@ struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesRequest {
9594
Status Validate() const {
9695
for (const auto& key : removals) {
9796
if (updates.contains(key)) {
98-
return Invalid("Duplicate key to update and remove: {}", key);
97+
return ValidationFailed("Duplicate key to update and remove: {}", key);
9998
}
10099
}
101100
return {};
@@ -113,11 +112,11 @@ struct ICEBERG_REST_EXPORT RegisterTableRequest {
113112
/// \brief Validates the RegisterTableRequest.
114113
Status Validate() const {
115114
if (name.empty()) {
116-
return Invalid("Missing table name");
115+
return ValidationFailed("Missing table name");
117116
}
118117

119118
if (metadata_location.empty()) {
120-
return Invalid("Empty metadata location");
119+
return ValidationFailed("Empty metadata location");
121120
}
122121

123122
return {};
@@ -154,10 +153,10 @@ struct ICEBERG_REST_EXPORT CreateTableRequest {
154153
/// \brief Validates the CreateTableRequest.
155154
Status Validate() const {
156155
if (name.empty()) {
157-
return Invalid("Missing table name");
156+
return ValidationFailed("Missing table name");
158157
}
159158
if (!schema) {
160-
return Invalid("Missing schema");
159+
return ValidationFailed("Missing schema");
161160
}
162161
return {};
163162
}
@@ -178,7 +177,7 @@ struct ICEBERG_REST_EXPORT LoadTableResult {
178177
/// \brief Validates the LoadTableResult.
179178
Status Validate() const {
180179
if (!metadata) {
181-
return Invalid("Invalid metadata: null");
180+
return ValidationFailed("Invalid metadata: null");
182181
}
183182
return {};
184183
}
@@ -251,8 +250,8 @@ struct ICEBERG_REST_EXPORT ListTablesResponse {
251250
/// \brief Request to commit changes to a table.
252251
struct ICEBERG_REST_EXPORT CommitTableRequest {
253252
TableIdentifier identifier;
254-
std::vector<std::shared_ptr<TableRequirement>> requirements;
255-
std::vector<std::shared_ptr<TableUpdate>> updates;
253+
std::vector<std::shared_ptr<TableRequirement>> requirements; // required
254+
std::vector<std::shared_ptr<TableUpdate>> updates; // required
256255

257256
/// \brief Validates the CommitTableRequest.
258257
Status Validate() const { return {}; }
@@ -262,14 +261,16 @@ struct ICEBERG_REST_EXPORT CommitTableRequest {
262261

263262
/// \brief Response from committing changes to a table.
264263
struct ICEBERG_REST_EXPORT CommitTableResponse {
265-
std::string metadata_location;
264+
std::string metadata_location; // required
266265
std::shared_ptr<TableMetadata> metadata; // required
267-
// TODO(Li Feiyang): Add std::shared_ptr<StorageCredential> storage_credential;
268266

269267
/// \brief Validates the CommitTableResponse.
270268
Status Validate() const {
269+
if (metadata_location.empty()) {
270+
return ValidationFailed("Invalid metadata location: empty");
271+
}
271272
if (!metadata) {
272-
return Invalid("Invalid metadata: null");
273+
return ValidationFailed("Invalid metadata: null");
273274
}
274275
return {};
275276
}

0 commit comments

Comments
 (0)