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
31#include "iceberg/catalog/rest/iceberg_rest_export.h"
32#include "iceberg/result.h"
33#include "iceberg/storage_credential.h"
35#include "iceberg/type_fwd.h"
36#include "iceberg/util/macros.h"
37
40
41namespace iceberg::rest {
42
44enum class PlanStatus {
45 kSubmitted,
46 kCompleted,
47 kCancelled,
48 kFailed,
49};
50
51ICEBERG_REST_EXPORT std::string_view ToString(PlanStatus status);
52ICEBERG_REST_EXPORT Result<PlanStatus> PlanStatusFromString(std::string_view status_str);
53
55struct ICEBERG_REST_EXPORT CatalogConfig {
56 std::unordered_map<std::string, std::string> defaults; // required
57 std::unordered_map<std::string, std::string> overrides; // required
58 std::vector<Endpoint> endpoints;
59
61 Status Validate() const { return {}; }
62
63 bool operator==(const CatalogConfig&) const = default;
64};
65
67struct ICEBERG_REST_EXPORT ErrorResponse {
68 uint32_t code; // required
69 std::string type; // required
70 std::string message; // required
71 std::vector<std::string> stack;
72
74 Status Validate() const {
75 if (message.empty() || type.empty()) {
76 return ValidationFailed("Invalid error response: missing required fields");
77 }
78
79 if (code < 400 || code > 600) {
80 return ValidationFailed(
81 "Invalid error response: code {} is out of range [400, 600]", code);
82 }
83
84 // stack is optional, no validation needed
85 return {};
86 }
87
88 bool operator==(const ErrorResponse&) const = default;
89};
90
92struct ICEBERG_REST_EXPORT CreateNamespaceRequest {
93 Namespace namespace_; // required
94 std::unordered_map<std::string, std::string> properties;
95
97 Status Validate() const { return {}; }
98
99 bool operator==(const CreateNamespaceRequest&) const = default;
100};
101
103struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesRequest {
104 std::vector<std::string> removals;
105 std::unordered_map<std::string, std::string> updates;
106
108 Status Validate() const {
109 for (const auto& key : removals) {
110 if (updates.contains(key)) {
111 return ValidationFailed("Duplicate key to update and remove: {}", key);
112 }
113 }
114 return {};
115 }
116
117 bool operator==(const UpdateNamespacePropertiesRequest&) const = default;
118};
119
121struct ICEBERG_REST_EXPORT RegisterTableRequest {
122 std::string name; // required
123 std::string metadata_location; // required
124 bool overwrite = false;
125
127 Status Validate() const {
128 if (name.empty()) {
129 return ValidationFailed("Missing table name");
130 }
131
132 if (metadata_location.empty()) {
133 return ValidationFailed("Empty metadata location");
134 }
135
136 return {};
137 }
138
139 bool operator==(const RegisterTableRequest&) const = default;
140};
141
143struct ICEBERG_REST_EXPORT RenameTableRequest {
144 TableIdentifier source; // required
145 TableIdentifier destination; // required
146
148 Status Validate() const {
149 ICEBERG_RETURN_UNEXPECTED(source.Validate());
150 ICEBERG_RETURN_UNEXPECTED(destination.Validate());
151 return {};
152 }
153
154 bool operator==(const RenameTableRequest&) const = default;
155};
156
158struct ICEBERG_REST_EXPORT CreateTableRequest {
159 std::string name; // required
160 std::string location;
161 std::shared_ptr<Schema> schema; // required
162 std::shared_ptr<PartitionSpec> partition_spec;
163 std::shared_ptr<SortOrder> write_order;
164 bool stage_create = false;
165 std::unordered_map<std::string, std::string> properties;
166
168 Status Validate() const {
169 if (name.empty()) {
170 return ValidationFailed("Missing table name");
171 }
172 if (!schema) {
173 return ValidationFailed("Missing schema");
174 }
175 return {};
176 }
177
178 bool operator==(const CreateTableRequest& other) const;
179};
180
182using PageToken = std::string;
183
185struct ICEBERG_REST_EXPORT LoadTableResult {
186 std::string metadata_location;
187 std::shared_ptr<TableMetadata> metadata; // required
188 std::unordered_map<std::string, std::string> config;
190 std::vector<StorageCredential> storage_credentials;
191
193 Status Validate() const {
194 if (!metadata) {
195 return ValidationFailed("Invalid metadata: null");
196 }
197 for (const auto& credential : storage_credentials) {
198 ICEBERG_RETURN_UNEXPECTED(credential.Validate());
199 }
200 return {};
201 }
202
203 bool operator==(const LoadTableResult& other) const;
204};
205
208
211
213struct ICEBERG_REST_EXPORT ListNamespacesResponse {
214 PageToken next_page_token;
215 std::vector<Namespace> namespaces;
216
218 Status Validate() const { return {}; }
219
220 bool operator==(const ListNamespacesResponse&) const = default;
221};
222
224struct ICEBERG_REST_EXPORT CreateNamespaceResponse {
225 Namespace namespace_; // required
226 std::unordered_map<std::string, std::string> properties;
227
229 Status Validate() const { return {}; }
230
231 bool operator==(const CreateNamespaceResponse&) const = default;
232};
233
235struct ICEBERG_REST_EXPORT GetNamespaceResponse {
236 Namespace namespace_; // required
237 std::unordered_map<std::string, std::string> properties;
238
240 Status Validate() const { return {}; }
241
242 bool operator==(const GetNamespaceResponse&) const = default;
243};
244
246struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesResponse {
247 std::vector<std::string> updated; // required
248 std::vector<std::string> removed; // required
249 std::vector<std::string> missing;
250
252 Status Validate() const { return {}; }
253
254 bool operator==(const UpdateNamespacePropertiesResponse&) const = default;
255};
256
258struct ICEBERG_REST_EXPORT ListTablesResponse {
259 PageToken next_page_token;
260 std::vector<TableIdentifier> identifiers;
261
263 Status Validate() const { return {}; }
264
265 bool operator==(const ListTablesResponse&) const = default;
266};
267
269struct ICEBERG_REST_EXPORT CommitTableRequest {
270 TableIdentifier identifier;
271 std::vector<std::shared_ptr<TableRequirement>> requirements; // required
272 std::vector<std::shared_ptr<TableUpdate>> updates; // required
273
275 Status Validate() const { return {}; }
276
277 bool operator==(const CommitTableRequest& other) const;
278};
279
281struct ICEBERG_REST_EXPORT CommitTableResponse {
282 std::string metadata_location; // required
283 std::shared_ptr<TableMetadata> metadata; // required
284
286 Status Validate() const {
287 if (metadata_location.empty()) {
288 return ValidationFailed("Invalid metadata location: empty");
289 }
290 if (!metadata) {
291 return ValidationFailed("Invalid metadata: null");
292 }
293 return {};
294 }
295
296 bool operator==(const CommitTableResponse& other) const;
297};
298
300struct ICEBERG_REST_EXPORT OAuthTokenResponse {
301 std::string access_token; // required
302 std::string token_type; // required, "bearer" or "N_A"
303 std::optional<int64_t> expires_in_secs; // optional, seconds until expiration
304 std::string issued_token_type; // optional, for token exchange
305 std::string refresh_token; // optional
306 std::string scope; // optional
307
309 Status Validate() const;
310
311 bool operator==(const OAuthTokenResponse&) const = default;
312};
313
315struct ICEBERG_REST_EXPORT PlanTableScanRequest {
316 std::optional<int64_t> snapshot_id;
317 std::vector<std::string> select;
318 std::shared_ptr<Expression> filter;
319 bool case_sensitive = true;
320 bool use_snapshot_schema = false;
321 std::optional<int64_t> start_snapshot_id;
322 std::optional<int64_t> end_snapshot_id;
323 std::vector<std::string> stats_fields;
324 std::optional<int64_t> min_rows_requested;
325
326 Status Validate() const;
327
328 bool operator==(const PlanTableScanRequest&) const;
329};
330
333struct ICEBERG_REST_EXPORT PlanTableScanResponse {
334 std::optional<std::vector<std::string>> plan_tasks;
335 std::optional<std::vector<std::shared_ptr<FileScanTask>>> file_scan_tasks;
336 std::vector<std::shared_ptr<DataFile>> delete_files;
337 PlanStatus plan_status = PlanStatus::kCompleted;
338 std::string plan_id;
339 std::optional<ErrorResponse> error;
340 // TODO(sandeepg): Add storage credentials and bind scan FileIO to them.
341
342 Status Validate() const;
343
344 bool operator==(const PlanTableScanResponse&) const;
345};
346
349struct ICEBERG_REST_EXPORT FetchPlanningResultResponse {
350 std::optional<std::vector<std::string>> plan_tasks;
351 std::optional<std::vector<std::shared_ptr<FileScanTask>>> file_scan_tasks;
352 std::vector<std::shared_ptr<DataFile>> delete_files;
353 PlanStatus plan_status = PlanStatus::kCompleted;
354 std::optional<ErrorResponse> error;
355 // TODO(sandeepg): Add storage credentials and bind scan FileIO to them.
356
357 Status Validate() const;
358
359 bool operator==(const FetchPlanningResultResponse&) const;
360};
361
363struct ICEBERG_REST_EXPORT FetchScanTasksRequest {
364 std::string planTask;
365
366 Status Validate() const;
367
368 bool operator==(const FetchScanTasksRequest&) const;
369};
370
372struct ICEBERG_REST_EXPORT FetchScanTasksResponse {
373 std::optional<std::vector<std::string>> plan_tasks;
374 std::optional<std::vector<std::shared_ptr<FileScanTask>>> file_scan_tasks;
375 std::vector<std::shared_ptr<DataFile>> delete_files;
376
377 Status Validate() const;
378
379 bool operator==(const FetchScanTasksResponse&) const;
380};
381
382} // 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:55
Status Validate() const
Validates the CatalogConfig.
Definition types.h:61
Request to commit changes to a table.
Definition types.h:269
Status Validate() const
Validates the CommitTableRequest.
Definition types.h:275
Response from committing changes to a table.
Definition types.h:281
Status Validate() const
Validates the CommitTableResponse.
Definition types.h:286
Request to create a namespace.
Definition types.h:92
Status Validate() const
Validates the CreateNamespaceRequest.
Definition types.h:97
Response body after creating a namespace.
Definition types.h:224
Status Validate() const
Validates the CreateNamespaceResponse.
Definition types.h:229
Request to create a table.
Definition types.h:158
Status Validate() const
Validates the CreateTableRequest.
Definition types.h:168
JSON error payload returned in a response with further details on the error.
Definition types.h:67
Status Validate() const
Validates the ErrorResponse.
Definition types.h:74
Response from polling an asynchronous scan plan, including current status and available scan tasks.
Definition types.h:349
Request to fetch the scan tasks for a given plan task token.
Definition types.h:363
Response containing the file scan tasks for a given plan task token.
Definition types.h:372
Response body for loading namespace properties.
Definition types.h:235
Status Validate() const
Validates the GetNamespaceResponse.
Definition types.h:240
Response body for listing namespaces.
Definition types.h:213
Status Validate() const
Validates the ListNamespacesResponse.
Definition types.h:218
Response body for listing tables in a namespace.
Definition types.h:258
Status Validate() const
Validates the ListTablesResponse.
Definition types.h:263
Result body for table create/load/register APIs.
Definition types.h:185
Status Validate() const
Validates the LoadTableResult.
Definition types.h:193
std::vector< StorageCredential > storage_credentials
Vended storage credentials, one per URI prefix; empty if none.
Definition types.h:190
Response from an OAuth2 token endpoint.
Definition types.h:300
Request to initiate a server-side scan planning operation.
Definition types.h:315
Response from initiating a scan planning operation, including plan status and initial scan tasks.
Definition types.h:333
Request to register a table.
Definition types.h:121
Status Validate() const
Validates the RegisterTableRequest.
Definition types.h:127
Request to rename a table.
Definition types.h:143
Status Validate() const
Validates the RenameTableRequest.
Definition types.h:148
Update or delete namespace properties request.
Definition types.h:103
Status Validate() const
Validates the UpdateNamespacePropertiesRequest.
Definition types.h:108
Response body after updating namespace properties.
Definition types.h:246
Status Validate() const
Validates the UpdateNamespacePropertiesResponse.
Definition types.h:252
std::string PageToken
An opaque token that allows clients to make use of pagination for list APIs.
Definition types.h:182
PlanStatus
Status of a REST server-side scan planning operation.
Definition types.h:44