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 <string_view>
27#include <unordered_map>
28#include <vector>
29
32#include "iceberg/labels.h"
33#include "iceberg/result.h"
36#include "iceberg/type_fwd.h"
37#include "iceberg/util/macros.h"
38
41
42namespace iceberg::rest {
43
45enum class PlanStatus {
46 kSubmitted,
47 kCompleted,
48 kCancelled,
49 kFailed,
50};
51
52ICEBERG_REST_EXPORT std::string_view ToString(PlanStatus status);
53ICEBERG_REST_EXPORT Result<PlanStatus> PlanStatusFromString(std::string_view status_str);
54
56struct ICEBERG_REST_EXPORT CatalogConfig {
57 std::unordered_map<std::string, std::string> defaults; // required
58 std::unordered_map<std::string, std::string> overrides; // required
59 std::vector<Endpoint> endpoints;
60
62 Status Validate() const { return {}; }
63
64 bool operator==(const CatalogConfig&) const = default;
65};
66
68struct ICEBERG_REST_EXPORT ErrorResponse {
69 uint32_t code; // required
70 std::string type; // required
71 std::string message; // required
72 std::vector<std::string> stack;
73
75 Status Validate() const {
76 if (message.empty() || type.empty()) {
77 return ValidationFailed("Invalid error response: missing required fields");
78 }
79
80 if (code < 400 || code > 600) {
81 return ValidationFailed(
82 "Invalid error response: code {} is out of range [400, 600]", code);
83 }
84
85 // stack is optional, no validation needed
86 return {};
87 }
88
89 bool operator==(const ErrorResponse&) const = default;
90};
91
93struct ICEBERG_REST_EXPORT CreateNamespaceRequest {
94 Namespace namespace_; // required
95 std::unordered_map<std::string, std::string> properties;
96
98 Status Validate() const { return {}; }
99
100 bool operator==(const CreateNamespaceRequest&) const = default;
101};
102
104struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesRequest {
105 std::vector<std::string> removals;
106 std::unordered_map<std::string, std::string> updates;
107
109 Status Validate() const {
110 for (const auto& key : removals) {
111 if (updates.contains(key)) {
112 return ValidationFailed("Duplicate key to update and remove: {}", key);
113 }
114 }
115 return {};
116 }
117
118 bool operator==(const UpdateNamespacePropertiesRequest&) const = default;
119};
120
122struct ICEBERG_REST_EXPORT RegisterTableRequest {
123 std::string name; // required
124 std::string metadata_location; // required
125 bool overwrite = false;
126
128 Status Validate() const {
129 if (name.empty()) {
130 return ValidationFailed("Missing table name");
131 }
132
133 if (metadata_location.empty()) {
134 return ValidationFailed("Empty metadata location");
135 }
136
137 return {};
138 }
139
140 bool operator==(const RegisterTableRequest&) const = default;
141};
142
144struct ICEBERG_REST_EXPORT RenameTableRequest {
145 TableIdentifier source; // required
146 TableIdentifier destination; // required
147
149 Status Validate() const {
150 ICEBERG_RETURN_UNEXPECTED(source.Validate());
151 ICEBERG_RETURN_UNEXPECTED(destination.Validate());
152 return {};
153 }
154
155 bool operator==(const RenameTableRequest&) const = default;
156};
157
159struct ICEBERG_REST_EXPORT CreateTableRequest {
160 std::string name; // required
161 std::string location;
162 std::shared_ptr<Schema> schema; // required
163 std::shared_ptr<PartitionSpec> partition_spec;
164 std::shared_ptr<SortOrder> write_order;
165 bool stage_create = false;
166 std::unordered_map<std::string, std::string> properties;
167
169 Status Validate() const {
170 if (name.empty()) {
171 return ValidationFailed("Missing table name");
172 }
173 if (!schema) {
174 return ValidationFailed("Missing schema");
175 }
176 return {};
177 }
178
179 bool operator==(const CreateTableRequest& other) const;
180};
181
183using PageToken = std::string;
184
186struct ICEBERG_REST_EXPORT LoadTableResult {
187 std::string metadata_location;
188 std::shared_ptr<TableMetadata> metadata; // required
189 std::unordered_map<std::string, std::string> config;
191 std::vector<StorageCredential> storage_credentials;
194
196 Status Validate() const {
197 if (!metadata) {
198 return ValidationFailed("Invalid metadata: null");
199 }
200 for (const auto& credential : storage_credentials) {
201 ICEBERG_RETURN_UNEXPECTED(credential.Validate());
202 }
203 return {};
204 }
205
206 bool operator==(const LoadTableResult& other) const;
207};
208
211
214
216struct ICEBERG_REST_EXPORT LoadCredentialsResponse {
217 std::vector<StorageCredential> storage_credentials;
218
220 Status Validate() const {
221 for (const auto& credential : storage_credentials) {
222 ICEBERG_RETURN_UNEXPECTED(credential.Validate());
223 }
224 return {};
225 }
226
227 bool operator==(const LoadCredentialsResponse& other) const = default;
228};
229
231struct ICEBERG_REST_EXPORT ListNamespacesResponse {
232 PageToken next_page_token;
233 std::vector<Namespace> namespaces;
234
236 Status Validate() const { return {}; }
237
238 bool operator==(const ListNamespacesResponse&) const = default;
239};
240
242struct ICEBERG_REST_EXPORT CreateNamespaceResponse {
243 Namespace namespace_; // required
244 std::unordered_map<std::string, std::string> properties;
245
247 Status Validate() const { return {}; }
248
249 bool operator==(const CreateNamespaceResponse&) const = default;
250};
251
253struct ICEBERG_REST_EXPORT GetNamespaceResponse {
254 Namespace namespace_; // required
255 std::unordered_map<std::string, std::string> properties;
256
258 Status Validate() const { return {}; }
259
260 bool operator==(const GetNamespaceResponse&) const = default;
261};
262
264struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesResponse {
265 std::vector<std::string> updated; // required
266 std::vector<std::string> removed; // required
267 std::vector<std::string> missing;
268
270 Status Validate() const { return {}; }
271
272 bool operator==(const UpdateNamespacePropertiesResponse&) const = default;
273};
274
276struct ICEBERG_REST_EXPORT ListTablesResponse {
277 PageToken next_page_token;
278 std::vector<TableIdentifier> identifiers;
279
281 Status Validate() const { return {}; }
282
283 bool operator==(const ListTablesResponse&) const = default;
284};
285
287struct ICEBERG_REST_EXPORT CommitTableRequest {
288 TableIdentifier identifier;
289 std::vector<std::shared_ptr<TableRequirement>> requirements; // required
290 std::vector<std::shared_ptr<TableUpdate>> updates; // required
291
293 Status Validate() const { return {}; }
294
295 bool operator==(const CommitTableRequest& other) const;
296};
297
299struct ICEBERG_REST_EXPORT CommitTableResponse {
300 std::string metadata_location; // required
301 std::shared_ptr<TableMetadata> metadata; // required
302
304 Status Validate() const {
305 if (metadata_location.empty()) {
306 return ValidationFailed("Invalid metadata location: empty");
307 }
308 if (!metadata) {
309 return ValidationFailed("Invalid metadata: null");
310 }
311 return {};
312 }
313
314 bool operator==(const CommitTableResponse& other) const;
315};
316
318struct ICEBERG_REST_EXPORT OAuthTokenResponse {
319 std::string access_token; // required
320 std::string token_type; // required, "bearer" or "N_A"
321 std::optional<int64_t> expires_in_secs; // optional, seconds until expiration
322 std::string issued_token_type; // optional, for token exchange
323 std::string refresh_token; // optional
324 std::string scope; // optional
325
328
329 bool operator==(const OAuthTokenResponse&) const = default;
330};
331
333struct ICEBERG_REST_EXPORT PlanTableScanRequest {
334 std::optional<int64_t> snapshot_id;
335 std::vector<std::string> select;
336 std::shared_ptr<Expression> filter;
337 bool case_sensitive = true;
338 bool use_snapshot_schema = false;
339 std::optional<int64_t> start_snapshot_id;
340 std::optional<int64_t> end_snapshot_id;
341 std::vector<std::string> stats_fields;
342 std::optional<int64_t> min_rows_requested;
343
344 Status Validate() const;
345
346 bool operator==(const PlanTableScanRequest&) const;
347};
348
351struct ICEBERG_REST_EXPORT PlanTableScanResponse {
352 std::optional<std::vector<std::string>> plan_tasks;
353 std::optional<std::vector<std::shared_ptr<FileScanTask>>> file_scan_tasks;
354 std::vector<std::shared_ptr<DataFile>> delete_files;
355 PlanStatus plan_status = PlanStatus::kCompleted;
356 std::string plan_id;
357 std::optional<ErrorResponse> error;
358 std::vector<StorageCredential> storage_credentials;
359
360 Status Validate() const;
361
362 bool operator==(const PlanTableScanResponse&) const;
363};
364
367struct ICEBERG_REST_EXPORT FetchPlanningResultResponse {
368 std::optional<std::vector<std::string>> plan_tasks;
369 std::optional<std::vector<std::shared_ptr<FileScanTask>>> file_scan_tasks;
370 std::vector<std::shared_ptr<DataFile>> delete_files;
371 PlanStatus plan_status = PlanStatus::kCompleted;
372 std::optional<ErrorResponse> error;
373 std::vector<StorageCredential> storage_credentials;
374
375 Status Validate() const;
376
377 bool operator==(const FetchPlanningResultResponse&) const;
378};
379
381struct ICEBERG_REST_EXPORT FetchScanTasksRequest {
382 std::string planTask;
383
384 Status Validate() const;
385
386 bool operator==(const FetchScanTasksRequest&) const;
387};
388
390struct ICEBERG_REST_EXPORT FetchScanTasksResponse {
391 std::optional<std::vector<std::string>> plan_tasks;
392 std::optional<std::vector<std::shared_ptr<FileScanTask>>> file_scan_tasks;
393 std::vector<std::shared_ptr<DataFile>> delete_files;
394
395 Status Validate() const;
396
397 bool operator==(const FetchScanTasksResponse&) const;
398};
399
400} // namespace iceberg::rest
Definition expected.h:1199
Define symbol visibility macros for the REST catalog library.
Catalog-provided labels for tables and their fields.
Define common Iceberg utility macros.
REST catalog APIs.
Definition auth_manager.h:34
constexpr std::string_view ToString(HttpMethod method)
Convert HttpMethod to string representation.
Definition http_request.h:41
std::string PageToken
An opaque token that allows clients to make use of pagination for list APIs.
Definition types.h:183
PlanStatus
Status of a REST server-side scan planning operation.
Definition types.h:45
Define Result, Status, and error helpers.
Define storage credential metadata.
Optional catalog-provided labels returned when a table is loaded.
Definition labels.h:46
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:56
Status Validate() const
Validates the CatalogConfig.
Definition types.h:62
Request to commit changes to a table.
Definition types.h:287
Status Validate() const
Validates the CommitTableRequest.
Definition types.h:293
Response from committing changes to a table.
Definition types.h:299
Status Validate() const
Validates the CommitTableResponse.
Definition types.h:304
Request to create a namespace.
Definition types.h:93
Status Validate() const
Validates the CreateNamespaceRequest.
Definition types.h:98
Response body after creating a namespace.
Definition types.h:242
Status Validate() const
Validates the CreateNamespaceResponse.
Definition types.h:247
Request to create a table.
Definition types.h:159
Status Validate() const
Validates the CreateTableRequest.
Definition types.h:169
JSON error payload returned in a response with further details on the error.
Definition types.h:68
Status Validate() const
Validates the ErrorResponse.
Definition types.h:75
Response from polling an asynchronous scan plan, including current status and available scan tasks.
Definition types.h:367
Request to fetch the scan tasks for a given plan task token.
Definition types.h:381
Response containing the file scan tasks for a given plan task token.
Definition types.h:390
Response body for loading namespace properties.
Definition types.h:253
Status Validate() const
Validates the GetNamespaceResponse.
Definition types.h:258
Response body for listing namespaces.
Definition types.h:231
Status Validate() const
Validates the ListNamespacesResponse.
Definition types.h:236
Response body for listing tables in a namespace.
Definition types.h:276
Status Validate() const
Validates the ListTablesResponse.
Definition types.h:281
Response body of the LoadCredentials API.
Definition types.h:216
Status Validate() const
Validates the LoadCredentialsResponse.
Definition types.h:220
Result body for table create/load/register APIs.
Definition types.h:186
Status Validate() const
Validates the LoadTableResult.
Definition types.h:196
Labels labels
Catalog-provided labels; empty if none.
Definition types.h:193
std::vector< StorageCredential > storage_credentials
Vended storage credentials, one per URI prefix; empty if none.
Definition types.h:191
Response from an OAuth2 token endpoint.
Definition types.h:318
Status Validate() const
Validates the token response.
Request to initiate a server-side scan planning operation.
Definition types.h:333
Response from initiating a scan planning operation, including plan status and initial scan tasks.
Definition types.h:351
Request to register a table.
Definition types.h:122
Status Validate() const
Validates the RegisterTableRequest.
Definition types.h:128
Request to rename a table.
Definition types.h:144
Status Validate() const
Validates the RenameTableRequest.
Definition types.h:149
Update or delete namespace properties request.
Definition types.h:104
Status Validate() const
Validates the UpdateNamespacePropertiesRequest.
Definition types.h:109
Response body after updating namespace properties.
Definition types.h:264
Status Validate() const
Validates the UpdateNamespacePropertiesResponse.
Definition types.h:270