iceberg-cpp
Loading...
Searching...
No Matches
endpoint.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <string>
23#include <string_view>
24
25#include "iceberg/catalog/rest/http_request.h"
26#include "iceberg/catalog/rest/iceberg_rest_export.h"
27#include "iceberg/result.h"
28
31
32namespace iceberg::rest {
33
38class ICEBERG_REST_EXPORT Endpoint {
39 public:
45 static Result<Endpoint> Make(HttpMethod method, std::string_view path);
46
52 static Result<Endpoint> FromString(std::string_view str);
53
55 constexpr HttpMethod method() const { return method_; }
56
58 std::string_view path() const { return path_; }
59
61 std::string ToString() const;
62
63 constexpr bool operator==(const Endpoint& other) const {
64 return method_ == other.method_ && path_ == other.path_;
65 }
66
67 // Namespace endpoints
68 static Endpoint ListNamespaces() {
69 return {HttpMethod::kGet, "/v1/{prefix}/namespaces"};
70 }
71 static Endpoint GetNamespaceProperties() {
72 return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}"};
73 }
74 static Endpoint NamespaceExists() {
75 return {HttpMethod::kHead, "/v1/{prefix}/namespaces/{namespace}"};
76 }
77 static Endpoint CreateNamespace() {
78 return {HttpMethod::kPost, "/v1/{prefix}/namespaces"};
79 }
80 static Endpoint UpdateNamespace() {
81 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/properties"};
82 }
83 static Endpoint DropNamespace() {
84 return {HttpMethod::kDelete, "/v1/{prefix}/namespaces/{namespace}"};
85 }
86
87 // Table endpoints
88 static Endpoint ListTables() {
89 return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}/tables"};
90 }
91 static Endpoint LoadTable() {
92 return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"};
93 }
94 static Endpoint TableExists() {
95 return {HttpMethod::kHead, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"};
96 }
97 static Endpoint CreateTable() {
98 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/tables"};
99 }
100 static Endpoint UpdateTable() {
101 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"};
102 }
103 static Endpoint DeleteTable() {
104 return {HttpMethod::kDelete, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"};
105 }
106 static Endpoint RenameTable() {
107 return {HttpMethod::kPost, "/v1/{prefix}/tables/rename"};
108 }
109 static Endpoint RegisterTable() {
110 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/register"};
111 }
112 static Endpoint ReportMetrics() {
113 return {HttpMethod::kPost,
114 "/v1/{prefix}/namespaces/{namespace}/tables/{table}/metrics"};
115 }
116 static Endpoint TableCredentials() {
117 return {HttpMethod::kGet,
118 "/v1/{prefix}/namespaces/{namespace}/tables/{table}/credentials"};
119 }
120
121 // Transaction endpoints
122 static Endpoint CommitTransaction() {
123 return {HttpMethod::kPost, "/v1/{prefix}/transactions/commit"};
124 }
125
126 // Scan planning endpoints
127 static Endpoint PlanTableScan() {
128 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/tables/{table}/plan"};
129 }
130
131 static Endpoint FetchPlanningResult() {
132 return {HttpMethod::kGet,
133 "/v1/{prefix}/namespaces/{namespace}/tables/{table}/plan/{plan-id}"};
134 }
135
136 static Endpoint CancelPlanning() {
137 return {HttpMethod::kDelete,
138 "/v1/{prefix}/namespaces/{namespace}/tables/{table}/plan/{plan-id}"};
139 }
140
141 static Endpoint FetchScanTasks() {
142 return {HttpMethod::kPost,
143 "/v1/{prefix}/namespaces/{namespace}/tables/{table}/tasks"};
144 }
145
146 private:
147 Endpoint(HttpMethod method, std::string_view path) : method_(method), path_(path) {}
148
149 HttpMethod method_;
150 std::string path_;
151};
152
153} // namespace iceberg::rest
154
155// Specialize std::hash for Endpoint
156namespace std {
157template <>
158struct hash<iceberg::rest::Endpoint> {
159 std::size_t operator()(const iceberg::rest::Endpoint& endpoint) const noexcept {
160 std::size_t h1 = std::hash<int32_t>{}(static_cast<int32_t>(endpoint.method()));
161 std::size_t h2 = std::hash<std::string_view>{}(endpoint.path());
162 return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
163 }
164};
165} // namespace std
An Endpoint is an immutable value object identifying a specific REST API operation....
Definition endpoint.h:38
constexpr HttpMethod method() const
Get the HTTP method.
Definition endpoint.h:55
std::string_view path() const
Get the path template.
Definition endpoint.h:58
STL namespace.