-
Notifications
You must be signed in to change notification settings - Fork 76
feat(rest): respect server-provided endpoints #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce743cc
feat: Implement server-provided endpoints configuration for REST
HeartLinked 9f4c681
fix ci
HeartLinked 8fc6e83
1
HeartLinked 305cde8
2
HeartLinked 8a78f4e
fix review
HeartLinked f095436
fix review
HeartLinked 910eb50
1
HeartLinked File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include "iceberg/catalog/rest/endpoint.h" | ||
|
|
||
| #include <format> | ||
| #include <string_view> | ||
|
|
||
| namespace iceberg::rest { | ||
|
|
||
| constexpr std::string_view ToString(HttpMethod method) { | ||
| switch (method) { | ||
| case HttpMethod::kGet: | ||
| return "GET"; | ||
| case HttpMethod::kPost: | ||
| return "POST"; | ||
| case HttpMethod::kPut: | ||
| return "PUT"; | ||
| case HttpMethod::kDelete: | ||
| return "DELETE"; | ||
| case HttpMethod::kHead: | ||
| return "HEAD"; | ||
| } | ||
| return "UNKNOWN"; | ||
| } | ||
|
|
||
| Result<Endpoint> Endpoint::Make(HttpMethod method, std::string_view path) { | ||
| if (path.empty()) { | ||
| return InvalidArgument("Endpoint cannot have empty path"); | ||
| } | ||
| return Endpoint(method, path); | ||
| } | ||
|
|
||
| Result<Endpoint> Endpoint::FromString(std::string_view str) { | ||
| auto space_pos = str.find(' '); | ||
| if (space_pos == std::string_view::npos || | ||
| str.find(' ', space_pos + 1) != std::string_view::npos) { | ||
| return InvalidArgument( | ||
| "Invalid endpoint format (must consist of two elements separated by a single " | ||
| "space): '{}'", | ||
| str); | ||
| } | ||
|
|
||
| auto method_str = str.substr(0, space_pos); | ||
| auto path_str = str.substr(space_pos + 1); | ||
|
|
||
| if (path_str.empty()) { | ||
| return InvalidArgument("Invalid endpoint format: path is empty"); | ||
| } | ||
|
|
||
| // Parse HTTP method | ||
| HttpMethod method; | ||
| if (method_str == "GET") { | ||
| method = HttpMethod::kGet; | ||
| } else if (method_str == "POST") { | ||
| method = HttpMethod::kPost; | ||
| } else if (method_str == "PUT") { | ||
| method = HttpMethod::kPut; | ||
| } else if (method_str == "DELETE") { | ||
| method = HttpMethod::kDelete; | ||
| } else if (method_str == "HEAD") { | ||
| method = HttpMethod::kHead; | ||
| } else { | ||
| return InvalidArgument("Invalid HTTP method: '{}'", method_str); | ||
| } | ||
|
|
||
| return Make(method, std::string(path_str)); | ||
| } | ||
|
|
||
| std::string Endpoint::ToString() const { | ||
| return std::format("{} {}", rest::ToString(method_), path_); | ||
| } | ||
|
|
||
| } // namespace iceberg::rest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| #include "iceberg/catalog/rest/iceberg_rest_export.h" | ||
| #include "iceberg/result.h" | ||
|
|
||
| /// \file iceberg/catalog/rest/endpoint.h | ||
| /// Endpoint definitions for Iceberg REST API operations. | ||
|
|
||
| namespace iceberg::rest { | ||
|
|
||
| /// \brief HTTP method enumeration. | ||
| enum class HttpMethod : uint8_t { kGet, kPost, kPut, kDelete, kHead }; | ||
|
|
||
| /// \brief Convert HttpMethod to string representation. | ||
| constexpr std::string_view ToString(HttpMethod method); | ||
|
|
||
| /// \brief An Endpoint is an immutable value object identifying a specific REST API | ||
| /// operation. It consists of: | ||
| /// - HTTP method (GET, POST, DELETE, etc.) | ||
| /// - Path template (e.g., "/v1/{prefix}/namespaces/{namespace}") | ||
| class ICEBERG_REST_EXPORT Endpoint { | ||
| public: | ||
| /// \brief Make an endpoint with method and path template. | ||
| /// | ||
| /// \param method HTTP method (GET, POST, etc.) | ||
| /// \param path Path template with placeholders (e.g., "/v1/{prefix}/tables") | ||
| /// \return Endpoint instance or error if invalid | ||
| static Result<Endpoint> Make(HttpMethod method, std::string_view path); | ||
|
|
||
| /// \brief Parse endpoint from string representation. "METHOD" have to be all | ||
| /// upper-cased. | ||
| /// | ||
| /// \param str String in format "METHOD /path/template" (e.g., "GET /v1/namespaces") | ||
| /// \return Endpoint instance or error if malformed. | ||
| static Result<Endpoint> FromString(std::string_view str); | ||
HeartLinked marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// \brief Get the HTTP method. | ||
| constexpr HttpMethod method() const { return method_; } | ||
|
|
||
| /// \brief Get the path template. | ||
| std::string_view path() const { return path_; } | ||
|
|
||
| /// \brief Serialize to "METHOD /path" format. | ||
| std::string ToString() const; | ||
|
|
||
| constexpr bool operator==(const Endpoint& other) const { | ||
| return method_ == other.method_ && path_ == other.path_; | ||
| } | ||
|
|
||
| // Namespace endpoints | ||
| static Endpoint ListNamespaces() { | ||
| return {HttpMethod::kGet, "/v1/{prefix}/namespaces"}; | ||
| } | ||
| static Endpoint GetNamespaceProperties() { | ||
| return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}"}; | ||
| } | ||
| static Endpoint NamespaceExists() { | ||
| return {HttpMethod::kHead, "/v1/{prefix}/namespaces/{namespace}"}; | ||
| } | ||
| static Endpoint CreateNamespace() { | ||
| return {HttpMethod::kPost, "/v1/{prefix}/namespaces"}; | ||
| } | ||
| static Endpoint UpdateNamespace() { | ||
| return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/properties"}; | ||
| } | ||
| static Endpoint DropNamespace() { | ||
| return {HttpMethod::kDelete, "/v1/{prefix}/namespaces/{namespace}"}; | ||
| } | ||
|
|
||
| // Table endpoints | ||
| static Endpoint ListTables() { | ||
| return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}/tables"}; | ||
| } | ||
| static Endpoint LoadTable() { | ||
| return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"}; | ||
| } | ||
| static Endpoint TableExists() { | ||
| return {HttpMethod::kHead, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"}; | ||
| } | ||
| static Endpoint CreateTable() { | ||
| return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/tables"}; | ||
| } | ||
| static Endpoint UpdateTable() { | ||
| return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"}; | ||
| } | ||
| static Endpoint DeleteTable() { | ||
| return {HttpMethod::kDelete, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"}; | ||
| } | ||
| static Endpoint RenameTable() { | ||
| return {HttpMethod::kPost, "/v1/{prefix}/tables/rename"}; | ||
| } | ||
| static Endpoint RegisterTable() { | ||
| return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/register"}; | ||
| } | ||
| static Endpoint ReportMetrics() { | ||
| return {HttpMethod::kPost, | ||
| "/v1/{prefix}/namespaces/{namespace}/tables/{table}/metrics"}; | ||
| } | ||
| static Endpoint TableCredentials() { | ||
| return {HttpMethod::kGet, | ||
| "/v1/{prefix}/namespaces/{namespace}/tables/{table}/credentials"}; | ||
| } | ||
|
|
||
| // Transaction endpoints | ||
| static Endpoint CommitTransaction() { | ||
| return {HttpMethod::kPost, "/v1/{prefix}/transactions/commit"}; | ||
| } | ||
|
|
||
| private: | ||
| Endpoint(HttpMethod method, std::string_view path) : method_(method), path_(path) {} | ||
|
|
||
| HttpMethod method_; | ||
| std::string path_; | ||
| }; | ||
|
|
||
| } // namespace iceberg::rest | ||
|
|
||
| // Specialize std::hash for Endpoint | ||
| namespace std { | ||
| template <> | ||
| struct hash<iceberg::rest::Endpoint> { | ||
| std::size_t operator()(const iceberg::rest::Endpoint& endpoint) const noexcept { | ||
| std::size_t h1 = std::hash<int32_t>{}(static_cast<int32_t>(endpoint.method())); | ||
| std::size_t h2 = std::hash<std::string_view>{}(endpoint.path()); | ||
| return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2)); | ||
| } | ||
| }; | ||
| } // namespace std | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.