Skip to content

Commit 9edd089

Browse files
committed
feat: add basic REST Catalog request/response models
1 parent 9fa0d15 commit 9edd089

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
#pragma once
20+
21+
#include <memory>
22+
#include <optional>
23+
#include <string>
24+
#include <unordered_map>
25+
#include <vector>
26+
27+
#include "iceberg/catalog/rest/iceberg_rest_export.h"
28+
#include "iceberg/partition_spec.h"
29+
#include "iceberg/schema.h"
30+
#include "iceberg/sort_order.h"
31+
#include "iceberg/table_identifier.h"
32+
33+
namespace iceberg::rest {
34+
35+
/// \brief Request to create a namespace.
36+
/// \details Corresponds to **POST /v1/{prefix}/namespaces**.
37+
/// Allows creating a new namespace with optional properties.
38+
struct ICEBERG_REST_EXPORT CreateNamespaceRequest {
39+
Namespace namespace_; // required
40+
std::unordered_map<std::string, std::string> properties;
41+
};
42+
43+
/// \brief Request to update or remove namespace properties.
44+
/// \details Corresponds to **POST /v1/{prefix}/namespaces/{namespace}/properties**.
45+
/// Allows setting and/or removing namespace properties in a single call.
46+
/// Properties not listed in this request are left unchanged.
47+
struct ICEBERG_REST_EXPORT UpdateNamespaceRequest {
48+
std::vector<std::string> removals;
49+
std::unordered_map<std::string, std::string> updates;
50+
};
51+
52+
/// \brief Request to create a table.
53+
/// \details Corresponds to **POST /v1/{prefix}/namespaces/{namespace}/tables**.
54+
/// If `stage_create` is false, the table is created immediately.
55+
/// If `stage_create` is true, metadata is prepared and returned without committing,
56+
/// allowing a later transaction commit via the table commit endpoint.
57+
struct ICEBERG_REST_EXPORT CreateTableRequest {
58+
std::string name; // required
59+
std::string location;
60+
std::shared_ptr<Schema> schema; // required
61+
std::shared_ptr<PartitionSpec> partition_spec;
62+
std::shared_ptr<SortOrder> write_order;
63+
std::optional<bool> stage_create;
64+
std::unordered_map<std::string, std::string> properties;
65+
};
66+
67+
/// \brief Request to register an existing table.
68+
/// \details Corresponds to **POST /v1/{prefix}/namespaces/{namespace}/register**.
69+
/// Registers an existing table using a given metadata file location.
70+
struct ICEBERG_REST_EXPORT RegisterTableRequest {
71+
std::string name; // required
72+
std::string metadata_location; // required
73+
std::optional<bool> overwrite;
74+
};
75+
76+
/// \brief Request to rename a table.
77+
/// \details Corresponds to **POST /v1/{prefix}/tables/rename**.
78+
/// Moves or renames a table from the source identifier to the destination identifier.
79+
struct ICEBERG_REST_EXPORT RenameTableRequest {
80+
TableIdentifier source; // required
81+
TableIdentifier destination; // required
82+
};
83+
84+
} // namespace iceberg::rest
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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 <optional>
23+
#include <string>
24+
#include <unordered_map>
25+
#include <vector>
26+
27+
#include "iceberg/catalog/rest/iceberg_rest_export.h"
28+
#include "iceberg/table_identifier.h"
29+
#include "iceberg/table_metadata.h"
30+
31+
namespace iceberg::rest {
32+
33+
/// \brief An opaque token that allows clients to make use of pagination for list APIs.
34+
using PageToken = std::string;
35+
36+
/// \brief Result body for table create/load/register APIs.
37+
/// \details Matches **components/schemas/LoadTableResult** in the REST spec.
38+
struct ICEBERG_REST_EXPORT LoadTableResult {
39+
std::optional<std::string> metadata_location;
40+
TableMetadata metadata; // required
41+
std::unordered_map<std::string, std::string> config;
42+
// TODO(Li Feiyang): Add std::vector<StorageCredential> storage_credentials;
43+
};
44+
45+
/// \brief Alias of LoadTableResult used as the body of CreateTableResponse
46+
using CreateTableResponse = LoadTableResult;
47+
48+
/// \brief Alias of LoadTableResult used as the body of LoadTableResponse
49+
using LoadTableResponse = LoadTableResult;
50+
51+
/// \brief Alias of LoadTableResult used as the body of RegisterTableResponse
52+
using RegisterTableResponse = LoadTableResult;
53+
54+
/// \brief Response body for listing namespaces.
55+
/// Contains all namespaces and an optional pagination token.
56+
struct ICEBERG_REST_EXPORT ListNamespacesResponse {
57+
std::optional<PageToken> next_page_token;
58+
std::vector<Namespace> namespaces;
59+
};
60+
61+
/// \brief Response body after creating a namespace.
62+
/// \details Contains the created namespace and its resolved properties.
63+
struct ICEBERG_REST_EXPORT CreateNamespaceResponse {
64+
Namespace namespace_; // required
65+
std::unordered_map<std::string, std::string> properties;
66+
};
67+
68+
/// \brief Response body for loading namespace properties.
69+
/// \details Contains stored properties, may be null if unsupported by the server.
70+
struct ICEBERG_REST_EXPORT GetNamespaceResponse {
71+
Namespace namespace_; // required
72+
std::unordered_map<std::string, std::string> properties;
73+
};
74+
75+
/// \brief Response body after updating namespace properties.
76+
/// \details Lists keys that were updated, removed, or missing.
77+
struct ICEBERG_REST_EXPORT UpdateNamespacePropertiesResponse {
78+
std::vector<std::string> updated; // required
79+
std::vector<std::string> removed; // required
80+
std::vector<std::string> missing;
81+
};
82+
83+
/// \brief Response body for listing tables in a namespace.
84+
/// \details Contains all table identifiers and an optional pagination token.
85+
struct ICEBERG_REST_EXPORT ListTablesResponse {
86+
std::optional<PageToken> next_page_token;
87+
std::vector<TableIdentifier> identifiers;
88+
};
89+
90+
} // namespace iceberg::rest

0 commit comments

Comments
 (0)