This is an automated email from the ASF dual-hosted git repository.
gangwu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new 8bb85216 refactor(rest): add equality operators to REST types (#422)
8bb85216 is described below
commit 8bb852164ea1e1e5d2e1bc809c6822fb312bc0ca
Author: Feiyang Li <[email protected]>
AuthorDate: Thu Dec 18 17:33:02 2025 +0800
refactor(rest): add equality operators to REST types (#422)
---
src/iceberg/catalog/rest/types.h | 24 ++++++++++
src/iceberg/test/rest_json_internal_test.cc | 70 -----------------------------
2 files changed, 24 insertions(+), 70 deletions(-)
diff --git a/src/iceberg/catalog/rest/types.h b/src/iceberg/catalog/rest/types.h
index afcd65b9..867abc3d 100644
--- a/src/iceberg/catalog/rest/types.h
+++ b/src/iceberg/catalog/rest/types.h
@@ -44,6 +44,8 @@ struct ICEBERG_REST_EXPORT CatalogConfig {
/// \brief Validates the CatalogConfig.
Status Validate() const { return {}; }
+
+ bool operator==(const CatalogConfig&) const = default;
};
/// \brief JSON error payload returned in a response with further details on
the error.
@@ -66,6 +68,8 @@ struct ICEBERG_REST_EXPORT ErrorResponse {
// stack is optional, no validation needed
return {};
}
+
+ bool operator==(const ErrorResponse&) const = default;
};
/// \brief Request to create a namespace.
@@ -75,6 +79,8 @@ struct ICEBERG_REST_EXPORT CreateNamespaceRequest {
/// \brief Validates the CreateNamespaceRequest.
Status Validate() const { return {}; }
+
+ bool operator==(const CreateNamespaceRequest&) const = default;
};
/// \brief Update or delete namespace properties request.
@@ -91,6 +97,8 @@ struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesRequest {
}
return {};
}
+
+ bool operator==(const UpdateNamespacePropertiesRequest&) const = default;
};
/// \brief Request to register a table.
@@ -111,6 +119,8 @@ struct ICEBERG_REST_EXPORT RegisterTableRequest {
return {};
}
+
+ bool operator==(const RegisterTableRequest&) const = default;
};
/// \brief Request to rename a table.
@@ -124,6 +134,8 @@ struct ICEBERG_REST_EXPORT RenameTableRequest {
ICEBERG_RETURN_UNEXPECTED(destination.Validate());
return {};
}
+
+ bool operator==(const RenameTableRequest&) const = default;
};
/// \brief An opaque token that allows clients to make use of pagination for
list APIs.
@@ -143,6 +155,8 @@ struct ICEBERG_REST_EXPORT LoadTableResult {
}
return {};
}
+
+ bool operator==(const LoadTableResult&) const = default;
};
/// \brief Alias of LoadTableResult used as the body of CreateTableResponse
@@ -158,6 +172,8 @@ struct ICEBERG_REST_EXPORT ListNamespacesResponse {
/// \brief Validates the ListNamespacesResponse.
Status Validate() const { return {}; }
+
+ bool operator==(const ListNamespacesResponse&) const = default;
};
/// \brief Response body after creating a namespace.
@@ -167,6 +183,8 @@ struct ICEBERG_REST_EXPORT CreateNamespaceResponse {
/// \brief Validates the CreateNamespaceResponse.
Status Validate() const { return {}; }
+
+ bool operator==(const CreateNamespaceResponse&) const = default;
};
/// \brief Response body for loading namespace properties.
@@ -176,6 +194,8 @@ struct ICEBERG_REST_EXPORT GetNamespaceResponse {
/// \brief Validates the GetNamespaceResponse.
Status Validate() const { return {}; }
+
+ bool operator==(const GetNamespaceResponse&) const = default;
};
/// \brief Response body after updating namespace properties.
@@ -186,6 +206,8 @@ struct ICEBERG_REST_EXPORT
UpdateNamespacePropertiesResponse {
/// \brief Validates the UpdateNamespacePropertiesResponse.
Status Validate() const { return {}; }
+
+ bool operator==(const UpdateNamespacePropertiesResponse&) const = default;
};
/// \brief Response body for listing tables in a namespace.
@@ -195,6 +217,8 @@ struct ICEBERG_REST_EXPORT ListTablesResponse {
/// \brief Validates the ListTablesResponse.
Status Validate() const { return {}; }
+
+ bool operator==(const ListTablesResponse&) const = default;
};
} // namespace iceberg::rest
diff --git a/src/iceberg/test/rest_json_internal_test.cc
b/src/iceberg/test/rest_json_internal_test.cc
index f95ab09c..67350ebd 100644
--- a/src/iceberg/test/rest_json_internal_test.cc
+++ b/src/iceberg/test/rest_json_internal_test.cc
@@ -18,8 +18,6 @@
*/
#include <string>
-#include <unordered_map>
-#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -33,74 +31,6 @@
namespace iceberg::rest {
-// TODO(gangwu): perhaps add these equality operators to the types themselves?
-bool operator==(const CreateNamespaceRequest& lhs, const
CreateNamespaceRequest& rhs) {
- return lhs.namespace_.levels == rhs.namespace_.levels &&
- lhs.properties == rhs.properties;
-}
-
-bool operator==(const UpdateNamespacePropertiesRequest& lhs,
- const UpdateNamespacePropertiesRequest& rhs) {
- return lhs.removals == rhs.removals && lhs.updates == rhs.updates;
-}
-
-bool operator==(const RegisterTableRequest& lhs, const RegisterTableRequest&
rhs) {
- return lhs.name == rhs.name && lhs.metadata_location ==
rhs.metadata_location &&
- lhs.overwrite == rhs.overwrite;
-}
-
-bool operator==(const CreateNamespaceResponse& lhs, const
CreateNamespaceResponse& rhs) {
- return lhs.namespace_.levels == rhs.namespace_.levels &&
- lhs.properties == rhs.properties;
-}
-
-bool operator==(const GetNamespaceResponse& lhs, const GetNamespaceResponse&
rhs) {
- return lhs.namespace_.levels == rhs.namespace_.levels &&
- lhs.properties == rhs.properties;
-}
-
-bool operator==(const ListNamespacesResponse& lhs, const
ListNamespacesResponse& rhs) {
- if (lhs.namespaces.size() != rhs.namespaces.size()) return false;
- for (size_t i = 0; i < lhs.namespaces.size(); ++i) {
- if (lhs.namespaces[i].levels != rhs.namespaces[i].levels) return false;
- }
- return lhs.next_page_token == rhs.next_page_token;
-}
-
-bool operator==(const UpdateNamespacePropertiesResponse& lhs,
- const UpdateNamespacePropertiesResponse& rhs) {
- return lhs.updated == rhs.updated && lhs.removed == rhs.removed &&
- lhs.missing == rhs.missing;
-}
-
-bool operator==(const ListTablesResponse& lhs, const ListTablesResponse& rhs) {
- if (lhs.identifiers.size() != rhs.identifiers.size()) return false;
- for (size_t i = 0; i < lhs.identifiers.size(); ++i) {
- if (lhs.identifiers[i].ns.levels != rhs.identifiers[i].ns.levels ||
- lhs.identifiers[i].name != rhs.identifiers[i].name) {
- return false;
- }
- }
- return lhs.next_page_token == rhs.next_page_token;
-}
-
-bool operator==(const RenameTableRequest& lhs, const RenameTableRequest& rhs) {
- return lhs.source.ns.levels == rhs.source.ns.levels &&
- lhs.source.name == rhs.source.name &&
- lhs.destination.ns.levels == rhs.destination.ns.levels &&
- lhs.destination.name == rhs.destination.name;
-}
-
-bool operator==(const CatalogConfig& lhs, const CatalogConfig& rhs) {
- return lhs.overrides == rhs.overrides && lhs.defaults == rhs.defaults &&
- lhs.endpoints == rhs.endpoints;
-}
-
-bool operator==(const ErrorResponse& lhs, const ErrorResponse& rhs) {
- return lhs.message == rhs.message && lhs.type == rhs.type && lhs.code ==
rhs.code &&
- lhs.stack == rhs.stack;
-}
-
// Test parameter structure for roundtrip tests
template <typename Model>
struct JsonRoundTripParam {