Skip to content

Commit f095436

Browse files
committed
fix review
1 parent 8a78f4e commit f095436

4 files changed

Lines changed: 20 additions & 41 deletions

File tree

src/iceberg/catalog/rest/endpoint.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ constexpr std::string_view ToString(HttpMethod method) {
4040
return "UNKNOWN";
4141
}
4242

43-
Result<Endpoint> Endpoint::Make(HttpMethod method, std::string_view path_template) {
44-
if (path_template.empty()) {
45-
return InvalidArgument("Path template cannot be empty");
43+
Result<Endpoint> Endpoint::Make(HttpMethod method, std::string_view path) {
44+
if (path.empty()) {
45+
return InvalidArgument("Endpoint cannot have empty path");
4646
}
47-
return Endpoint(method, path_template);
47+
return Endpoint(method, path);
4848
}
4949

5050
Result<Endpoint> Endpoint::FromString(std::string_view str) {

src/iceberg/catalog/rest/endpoint.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class ICEBERG_REST_EXPORT Endpoint {
4545
/// \brief Make an endpoint with method and path template.
4646
///
4747
/// \param method HTTP method (GET, POST, etc.)
48-
/// \param path_template Path template with placeholders (e.g., "/v1/{prefix}/tables")
48+
/// \param path Path template with placeholders (e.g., "/v1/{prefix}/tables")
4949
/// \return Endpoint instance or error if invalid
50-
static Result<Endpoint> Make(HttpMethod method, std::string_view path_template);
50+
static Result<Endpoint> Make(HttpMethod method, std::string_view path);
5151

5252
/// \brief Parse endpoint from string representation. "METHOD" have to be all
5353
/// upper-cased.
@@ -137,7 +137,8 @@ class ICEBERG_REST_EXPORT Endpoint {
137137

138138
struct ICEBERG_REST_EXPORT EndpointHash {
139139
std::size_t operator()(const Endpoint& endpoint) const noexcept {
140-
return std::hash<std::string>()(endpoint.ToString());
140+
return std::hash<int32_t>()(static_cast<int32_t>(endpoint.method())) * 31 +
141+
std::hash<std::string_view>()(endpoint.path());
141142
}
142143
};
143144

src/iceberg/catalog/rest/rest_catalog.cc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "iceberg/catalog/rest/rest_catalog.h"
2121

2222
#include <memory>
23-
#include <set>
2423
#include <unordered_map>
24+
#include <unordered_set>
2525
#include <utility>
2626

2727
#include <nlohmann/json.hpp>
@@ -78,18 +78,15 @@ Result<CatalogConfig> FetchServerConfig(const ResourcePaths& paths,
7878
RestCatalog::~RestCatalog() = default;
7979

8080
Result<std::unique_ptr<RestCatalog>> RestCatalog::Make(
81-
const RestCatalogProperties& initial_config) {
82-
ICEBERG_ASSIGN_OR_RAISE(auto uri, initial_config.Uri());
81+
const RestCatalogProperties& config) {
82+
ICEBERG_ASSIGN_OR_RAISE(auto uri, config.Uri());
8383
ICEBERG_ASSIGN_OR_RAISE(
84-
auto paths,
85-
ResourcePaths::Make(std::string(TrimTrailingSlash(uri)),
86-
initial_config.Get(RestCatalogProperties::kPrefix)));
87-
// get the raw config from server
88-
ICEBERG_ASSIGN_OR_RAISE(auto server_config, FetchServerConfig(*paths, initial_config));
84+
auto paths, ResourcePaths::Make(std::string(TrimTrailingSlash(uri)),
85+
config.Get(RestCatalogProperties::kPrefix)));
86+
ICEBERG_ASSIGN_OR_RAISE(auto server_config, FetchServerConfig(*paths, config));
8987

90-
std::unique_ptr<RestCatalogProperties> final_config =
91-
RestCatalogProperties::FromMap(MergeConfigs(
92-
server_config.overrides, initial_config.configs(), server_config.defaults));
88+
std::unique_ptr<RestCatalogProperties> final_config = RestCatalogProperties::FromMap(
89+
MergeConfigs(server_config.overrides, config.configs(), server_config.defaults));
9390

9491
std::unordered_set<Endpoint, EndpointHash> endpoints;
9592
if (!server_config.endpoints.empty()) {
@@ -107,7 +104,7 @@ Result<std::unique_ptr<RestCatalog>> RestCatalog::Make(
107104
ICEBERG_RETURN_UNEXPECTED(paths->SetBaseUri(std::string(TrimTrailingSlash(final_uri))));
108105

109106
return std::unique_ptr<RestCatalog>(
110-
new RestCatalog(std::move(final_config), std::move(paths), endpoints));
107+
new RestCatalog(std::move(final_config), std::move(paths), std::move(endpoints)));
111108
}
112109

113110
RestCatalog::RestCatalog(std::unique_ptr<RestCatalogProperties> config,
@@ -193,9 +190,8 @@ Status RestCatalog::DropNamespace(const Namespace& ns) {
193190

194191
Result<bool> RestCatalog::NamespaceExists(const Namespace& ns) const {
195192
auto check = CheckEndpoint(supported_endpoints_, Endpoint::NamespaceExists());
196-
// If server does not support HEAD endpoint, fall back to GetNamespaceProperties
197193
if (!check.has_value()) {
198-
ICEBERG_ASSIGN_OR_RAISE(auto path, paths_->Namespace_(ns));
194+
// Fall back to GetNamespaceProperties
199195
auto result = GetNamespaceProperties(ns);
200196
if (!result.has_value() && result.error().kind == ErrorKind::kNoSuchNamespace) {
201197
return false;

src/iceberg/test/endpoint_test.cc

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TEST(EndpointTest, InvalidCreate) {
3030
// Empty path template should fail
3131
auto result = Endpoint::Make(HttpMethod::kGet, "");
3232
EXPECT_THAT(result, IsError(ErrorKind::kInvalidArgument));
33-
EXPECT_THAT(result, HasErrorMessage("Path template cannot be empty"));
33+
EXPECT_THAT(result, HasErrorMessage("Endpoint cannot have empty path"));
3434
}
3535

3636
TEST(EndpointTest, ValidFromString) {
@@ -42,24 +42,6 @@ TEST(EndpointTest, ValidFromString) {
4242
EXPECT_EQ(endpoint.path(), "/path");
4343
}
4444

45-
TEST(EndpointTest, ToStringRepresentation) {
46-
auto endpoint1 = Endpoint::Make(HttpMethod::kPost, "/path/of/resource");
47-
ASSERT_THAT(endpoint1, IsOk());
48-
EXPECT_EQ(endpoint1->ToString(), "POST /path/of/resource");
49-
50-
auto endpoint2 = Endpoint::Make(HttpMethod::kGet, "/");
51-
ASSERT_THAT(endpoint2, IsOk());
52-
EXPECT_EQ(endpoint2->ToString(), "GET /");
53-
54-
auto endpoint3 = Endpoint::Make(HttpMethod::kPut, "/");
55-
ASSERT_THAT(endpoint3, IsOk());
56-
EXPECT_EQ(endpoint3->ToString(), "PUT /");
57-
58-
auto endpoint4 = Endpoint::Make(HttpMethod::kPut, "/namespaces/{namespace}/{x}");
59-
ASSERT_THAT(endpoint4, IsOk());
60-
EXPECT_EQ(endpoint4->ToString(), "PUT /namespaces/{namespace}/{x}");
61-
}
62-
6345
// Test all HTTP methods
6446
TEST(EndpointTest, AllHttpMethods) {
6547
auto get = Endpoint::Make(HttpMethod::kGet, "/path");
@@ -181,7 +163,7 @@ TEST(EndpointTest, Equality) {
181163
EXPECT_NE(*endpoint1, *endpoint4);
182164
}
183165

184-
// Test string serialization (endpoints are represented as strings)
166+
// Test string serialization
185167
TEST(EndpointTest, ToStringFormat) {
186168
auto endpoint1 = Endpoint::Make(HttpMethod::kGet, "/v1/{prefix}/namespaces");
187169
ASSERT_THAT(endpoint1, IsOk());

0 commit comments

Comments
 (0)