From a7d4c5a69df194c06a4f2d5b00dd624c1eb3f824 Mon Sep 17 00:00:00 2001 From: Li Feiyang Date: Thu, 18 Dec 2025 15:00:24 +0800 Subject: [PATCH] refactor(rest): add equality operators to REST types --- 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 afcd65b97..867abc3d9 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 f95ab09cb..67350ebd3 100644 --- a/src/iceberg/test/rest_json_internal_test.cc +++ b/src/iceberg/test/rest_json_internal_test.cc @@ -18,8 +18,6 @@ */ #include -#include -#include #include #include @@ -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 struct JsonRoundTripParam {