Skip to content

Commit 8bb8521

Browse files
authored
refactor(rest): add equality operators to REST types (#422)
1 parent 25daf33 commit 8bb8521

File tree

2 files changed

+24
-70
lines changed

2 files changed

+24
-70
lines changed

src/iceberg/catalog/rest/types.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct ICEBERG_REST_EXPORT CatalogConfig {
4444

4545
/// \brief Validates the CatalogConfig.
4646
Status Validate() const { return {}; }
47+
48+
bool operator==(const CatalogConfig&) const = default;
4749
};
4850

4951
/// \brief JSON error payload returned in a response with further details on the error.
@@ -66,6 +68,8 @@ struct ICEBERG_REST_EXPORT ErrorResponse {
6668
// stack is optional, no validation needed
6769
return {};
6870
}
71+
72+
bool operator==(const ErrorResponse&) const = default;
6973
};
7074

7175
/// \brief Request to create a namespace.
@@ -75,6 +79,8 @@ struct ICEBERG_REST_EXPORT CreateNamespaceRequest {
7579

7680
/// \brief Validates the CreateNamespaceRequest.
7781
Status Validate() const { return {}; }
82+
83+
bool operator==(const CreateNamespaceRequest&) const = default;
7884
};
7985

8086
/// \brief Update or delete namespace properties request.
@@ -91,6 +97,8 @@ struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesRequest {
9197
}
9298
return {};
9399
}
100+
101+
bool operator==(const UpdateNamespacePropertiesRequest&) const = default;
94102
};
95103

96104
/// \brief Request to register a table.
@@ -111,6 +119,8 @@ struct ICEBERG_REST_EXPORT RegisterTableRequest {
111119

112120
return {};
113121
}
122+
123+
bool operator==(const RegisterTableRequest&) const = default;
114124
};
115125

116126
/// \brief Request to rename a table.
@@ -124,6 +134,8 @@ struct ICEBERG_REST_EXPORT RenameTableRequest {
124134
ICEBERG_RETURN_UNEXPECTED(destination.Validate());
125135
return {};
126136
}
137+
138+
bool operator==(const RenameTableRequest&) const = default;
127139
};
128140

129141
/// \brief An opaque token that allows clients to make use of pagination for list APIs.
@@ -143,6 +155,8 @@ struct ICEBERG_REST_EXPORT LoadTableResult {
143155
}
144156
return {};
145157
}
158+
159+
bool operator==(const LoadTableResult&) const = default;
146160
};
147161

148162
/// \brief Alias of LoadTableResult used as the body of CreateTableResponse
@@ -158,6 +172,8 @@ struct ICEBERG_REST_EXPORT ListNamespacesResponse {
158172

159173
/// \brief Validates the ListNamespacesResponse.
160174
Status Validate() const { return {}; }
175+
176+
bool operator==(const ListNamespacesResponse&) const = default;
161177
};
162178

163179
/// \brief Response body after creating a namespace.
@@ -167,6 +183,8 @@ struct ICEBERG_REST_EXPORT CreateNamespaceResponse {
167183

168184
/// \brief Validates the CreateNamespaceResponse.
169185
Status Validate() const { return {}; }
186+
187+
bool operator==(const CreateNamespaceResponse&) const = default;
170188
};
171189

172190
/// \brief Response body for loading namespace properties.
@@ -176,6 +194,8 @@ struct ICEBERG_REST_EXPORT GetNamespaceResponse {
176194

177195
/// \brief Validates the GetNamespaceResponse.
178196
Status Validate() const { return {}; }
197+
198+
bool operator==(const GetNamespaceResponse&) const = default;
179199
};
180200

181201
/// \brief Response body after updating namespace properties.
@@ -186,6 +206,8 @@ struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesResponse {
186206

187207
/// \brief Validates the UpdateNamespacePropertiesResponse.
188208
Status Validate() const { return {}; }
209+
210+
bool operator==(const UpdateNamespacePropertiesResponse&) const = default;
189211
};
190212

191213
/// \brief Response body for listing tables in a namespace.
@@ -195,6 +217,8 @@ struct ICEBERG_REST_EXPORT ListTablesResponse {
195217

196218
/// \brief Validates the ListTablesResponse.
197219
Status Validate() const { return {}; }
220+
221+
bool operator==(const ListTablesResponse&) const = default;
198222
};
199223

200224
} // namespace iceberg::rest

src/iceberg/test/rest_json_internal_test.cc

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919

2020
#include <string>
21-
#include <unordered_map>
22-
#include <vector>
2321

2422
#include <gmock/gmock.h>
2523
#include <gtest/gtest.h>
@@ -33,74 +31,6 @@
3331

3432
namespace iceberg::rest {
3533

36-
// TODO(gangwu): perhaps add these equality operators to the types themselves?
37-
bool operator==(const CreateNamespaceRequest& lhs, const CreateNamespaceRequest& rhs) {
38-
return lhs.namespace_.levels == rhs.namespace_.levels &&
39-
lhs.properties == rhs.properties;
40-
}
41-
42-
bool operator==(const UpdateNamespacePropertiesRequest& lhs,
43-
const UpdateNamespacePropertiesRequest& rhs) {
44-
return lhs.removals == rhs.removals && lhs.updates == rhs.updates;
45-
}
46-
47-
bool operator==(const RegisterTableRequest& lhs, const RegisterTableRequest& rhs) {
48-
return lhs.name == rhs.name && lhs.metadata_location == rhs.metadata_location &&
49-
lhs.overwrite == rhs.overwrite;
50-
}
51-
52-
bool operator==(const CreateNamespaceResponse& lhs, const CreateNamespaceResponse& rhs) {
53-
return lhs.namespace_.levels == rhs.namespace_.levels &&
54-
lhs.properties == rhs.properties;
55-
}
56-
57-
bool operator==(const GetNamespaceResponse& lhs, const GetNamespaceResponse& rhs) {
58-
return lhs.namespace_.levels == rhs.namespace_.levels &&
59-
lhs.properties == rhs.properties;
60-
}
61-
62-
bool operator==(const ListNamespacesResponse& lhs, const ListNamespacesResponse& rhs) {
63-
if (lhs.namespaces.size() != rhs.namespaces.size()) return false;
64-
for (size_t i = 0; i < lhs.namespaces.size(); ++i) {
65-
if (lhs.namespaces[i].levels != rhs.namespaces[i].levels) return false;
66-
}
67-
return lhs.next_page_token == rhs.next_page_token;
68-
}
69-
70-
bool operator==(const UpdateNamespacePropertiesResponse& lhs,
71-
const UpdateNamespacePropertiesResponse& rhs) {
72-
return lhs.updated == rhs.updated && lhs.removed == rhs.removed &&
73-
lhs.missing == rhs.missing;
74-
}
75-
76-
bool operator==(const ListTablesResponse& lhs, const ListTablesResponse& rhs) {
77-
if (lhs.identifiers.size() != rhs.identifiers.size()) return false;
78-
for (size_t i = 0; i < lhs.identifiers.size(); ++i) {
79-
if (lhs.identifiers[i].ns.levels != rhs.identifiers[i].ns.levels ||
80-
lhs.identifiers[i].name != rhs.identifiers[i].name) {
81-
return false;
82-
}
83-
}
84-
return lhs.next_page_token == rhs.next_page_token;
85-
}
86-
87-
bool operator==(const RenameTableRequest& lhs, const RenameTableRequest& rhs) {
88-
return lhs.source.ns.levels == rhs.source.ns.levels &&
89-
lhs.source.name == rhs.source.name &&
90-
lhs.destination.ns.levels == rhs.destination.ns.levels &&
91-
lhs.destination.name == rhs.destination.name;
92-
}
93-
94-
bool operator==(const CatalogConfig& lhs, const CatalogConfig& rhs) {
95-
return lhs.overrides == rhs.overrides && lhs.defaults == rhs.defaults &&
96-
lhs.endpoints == rhs.endpoints;
97-
}
98-
99-
bool operator==(const ErrorResponse& lhs, const ErrorResponse& rhs) {
100-
return lhs.message == rhs.message && lhs.type == rhs.type && lhs.code == rhs.code &&
101-
lhs.stack == rhs.stack;
102-
}
103-
10434
// Test parameter structure for roundtrip tests
10535
template <typename Model>
10636
struct JsonRoundTripParam {

0 commit comments

Comments
 (0)