iceberg-cpp
Loading...
Searching...
No Matches
types.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 <cstdint>
23#include <memory>
24#include <optional>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
30#include "iceberg/catalog/rest/iceberg_rest_export.h"
31#include "iceberg/result.h"
32#include "iceberg/schema.h"
34#include "iceberg/type_fwd.h"
35#include "iceberg/util/macros.h"
36
39
40namespace iceberg::rest {
41
43struct ICEBERG_REST_EXPORT CatalogConfig {
44 std::unordered_map<std::string, std::string> defaults; // required
45 std::unordered_map<std::string, std::string> overrides; // required
46 std::vector<Endpoint> endpoints;
47
49 Status Validate() const { return {}; }
50
51 bool operator==(const CatalogConfig&) const = default;
52};
53
55struct ICEBERG_REST_EXPORT ErrorResponse {
56 uint32_t code; // required
57 std::string type; // required
58 std::string message; // required
59 std::vector<std::string> stack;
60
62 Status Validate() const {
63 if (message.empty() || type.empty()) {
64 return ValidationFailed("Invalid error response: missing required fields");
65 }
66
67 if (code < 400 || code > 600) {
68 return ValidationFailed(
69 "Invalid error response: code {} is out of range [400, 600]", code);
70 }
71
72 // stack is optional, no validation needed
73 return {};
74 }
75
76 bool operator==(const ErrorResponse&) const = default;
77};
78
80struct ICEBERG_REST_EXPORT CreateNamespaceRequest {
81 Namespace namespace_; // required
82 std::unordered_map<std::string, std::string> properties;
83
85 Status Validate() const { return {}; }
86
87 bool operator==(const CreateNamespaceRequest&) const = default;
88};
89
91struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesRequest {
92 std::vector<std::string> removals;
93 std::unordered_map<std::string, std::string> updates;
94
96 Status Validate() const {
97 for (const auto& key : removals) {
98 if (updates.contains(key)) {
99 return ValidationFailed("Duplicate key to update and remove: {}", key);
100 }
101 }
102 return {};
103 }
104
105 bool operator==(const UpdateNamespacePropertiesRequest&) const = default;
106};
107
109struct ICEBERG_REST_EXPORT RegisterTableRequest {
110 std::string name; // required
111 std::string metadata_location; // required
112 bool overwrite = false;
113
115 Status Validate() const {
116 if (name.empty()) {
117 return ValidationFailed("Missing table name");
118 }
119
120 if (metadata_location.empty()) {
121 return ValidationFailed("Empty metadata location");
122 }
123
124 return {};
125 }
126
127 bool operator==(const RegisterTableRequest&) const = default;
128};
129
131struct ICEBERG_REST_EXPORT RenameTableRequest {
132 TableIdentifier source; // required
133 TableIdentifier destination; // required
134
136 Status Validate() const {
137 ICEBERG_RETURN_UNEXPECTED(source.Validate());
138 ICEBERG_RETURN_UNEXPECTED(destination.Validate());
139 return {};
140 }
141
142 bool operator==(const RenameTableRequest&) const = default;
143};
144
146struct ICEBERG_REST_EXPORT CreateTableRequest {
147 std::string name; // required
148 std::string location;
149 std::shared_ptr<Schema> schema; // required
150 std::shared_ptr<PartitionSpec> partition_spec;
151 std::shared_ptr<SortOrder> write_order;
152 bool stage_create = false;
153 std::unordered_map<std::string, std::string> properties;
154
156 Status Validate() const {
157 if (name.empty()) {
158 return ValidationFailed("Missing table name");
159 }
160 if (!schema) {
161 return ValidationFailed("Missing schema");
162 }
163 return {};
164 }
165
166 bool operator==(const CreateTableRequest& other) const;
167};
168
170using PageToken = std::string;
171
173struct ICEBERG_REST_EXPORT LoadTableResult {
174 std::string metadata_location;
175 std::shared_ptr<TableMetadata> metadata; // required
176 std::unordered_map<std::string, std::string> config;
177 // TODO(Li Feiyang): Add std::shared_ptr<StorageCredential> storage_credential;
178
180 Status Validate() const {
181 if (!metadata) {
182 return ValidationFailed("Invalid metadata: null");
183 }
184 return {};
185 }
186
187 bool operator==(const LoadTableResult& other) const;
188};
189
192
195
197struct ICEBERG_REST_EXPORT ListNamespacesResponse {
198 PageToken next_page_token;
199 std::vector<Namespace> namespaces;
200
202 Status Validate() const { return {}; }
203
204 bool operator==(const ListNamespacesResponse&) const = default;
205};
206
208struct ICEBERG_REST_EXPORT CreateNamespaceResponse {
209 Namespace namespace_; // required
210 std::unordered_map<std::string, std::string> properties;
211
213 Status Validate() const { return {}; }
214
215 bool operator==(const CreateNamespaceResponse&) const = default;
216};
217
219struct ICEBERG_REST_EXPORT GetNamespaceResponse {
220 Namespace namespace_; // required
221 std::unordered_map<std::string, std::string> properties;
222
224 Status Validate() const { return {}; }
225
226 bool operator==(const GetNamespaceResponse&) const = default;
227};
228
230struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesResponse {
231 std::vector<std::string> updated; // required
232 std::vector<std::string> removed; // required
233 std::vector<std::string> missing;
234
236 Status Validate() const { return {}; }
237
238 bool operator==(const UpdateNamespacePropertiesResponse&) const = default;
239};
240
242struct ICEBERG_REST_EXPORT ListTablesResponse {
243 PageToken next_page_token;
244 std::vector<TableIdentifier> identifiers;
245
247 Status Validate() const { return {}; }
248
249 bool operator==(const ListTablesResponse&) const = default;
250};
251
253struct ICEBERG_REST_EXPORT CommitTableRequest {
254 TableIdentifier identifier;
255 std::vector<std::shared_ptr<TableRequirement>> requirements; // required
256 std::vector<std::shared_ptr<TableUpdate>> updates; // required
257
259 Status Validate() const { return {}; }
260
261 bool operator==(const CommitTableRequest& other) const;
262};
263
265struct ICEBERG_REST_EXPORT CommitTableResponse {
266 std::string metadata_location; // required
267 std::shared_ptr<TableMetadata> metadata; // required
268
270 Status Validate() const {
271 if (metadata_location.empty()) {
272 return ValidationFailed("Invalid metadata location: empty");
273 }
274 if (!metadata) {
275 return ValidationFailed("Invalid metadata: null");
276 }
277 return {};
278 }
279
280 bool operator==(const CommitTableResponse& other) const;
281};
282
284struct ICEBERG_REST_EXPORT OAuthTokenResponse {
285 std::string access_token; // required
286 std::string token_type; // required, "bearer" or "N_A"
287 std::optional<int64_t> expires_in_secs; // optional, seconds until expiration
288 std::string issued_token_type; // optional, for token exchange
289 std::string refresh_token; // optional
290 std::string scope; // optional
291
293 Status Validate() const;
294
295 bool operator==(const OAuthTokenResponse&) const = default;
296};
297
298} // namespace iceberg::rest
A namespace in a catalog.
Definition table_identifier.h:35
Identifies a table in iceberg catalog.
Definition table_identifier.h:46
Status Validate() const
Validates the TableIdentifier.
Definition table_identifier.h:55
Server-provided configuration for the catalog.
Definition types.h:43
Status Validate() const
Validates the CatalogConfig.
Definition types.h:49
Request to commit changes to a table.
Definition types.h:253
Status Validate() const
Validates the CommitTableRequest.
Definition types.h:259
Response from committing changes to a table.
Definition types.h:265
Status Validate() const
Validates the CommitTableResponse.
Definition types.h:270
Request to create a namespace.
Definition types.h:80
Status Validate() const
Validates the CreateNamespaceRequest.
Definition types.h:85
Response body after creating a namespace.
Definition types.h:208
Status Validate() const
Validates the CreateNamespaceResponse.
Definition types.h:213
Request to create a table.
Definition types.h:146
Status Validate() const
Validates the CreateTableRequest.
Definition types.h:156
JSON error payload returned in a response with further details on the error.
Definition types.h:55
Status Validate() const
Validates the ErrorResponse.
Definition types.h:62
Response body for loading namespace properties.
Definition types.h:219
Status Validate() const
Validates the GetNamespaceResponse.
Definition types.h:224
Response body for listing namespaces.
Definition types.h:197
Status Validate() const
Validates the ListNamespacesResponse.
Definition types.h:202
Response body for listing tables in a namespace.
Definition types.h:242
Status Validate() const
Validates the ListTablesResponse.
Definition types.h:247
Result body for table create/load/register APIs.
Definition types.h:173
Status Validate() const
Validates the LoadTableResult.
Definition types.h:180
Response from an OAuth2 token endpoint.
Definition types.h:284
Request to register a table.
Definition types.h:109
Status Validate() const
Validates the RegisterTableRequest.
Definition types.h:115
Request to rename a table.
Definition types.h:131
Status Validate() const
Validates the RenameTableRequest.
Definition types.h:136
Update or delete namespace properties request.
Definition types.h:91
Status Validate() const
Validates the UpdateNamespacePropertiesRequest.
Definition types.h:96
Response body after updating namespace properties.
Definition types.h:230
Status Validate() const
Validates the UpdateNamespacePropertiesResponse.
Definition types.h:236
std::string PageToken
An opaque token that allows clients to make use of pagination for list APIs.
Definition types.h:170