iceberg-cpp
Loading...
Searching...
No Matches
rest_catalog.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 <functional>
23#include <memory>
24#include <optional>
25#include <string>
26#include <unordered_set>
27
28#include "iceberg/catalog.h"
35#include "iceberg/labels.h"
36#include "iceberg/result.h"
38#include "iceberg/type_fwd.h"
39
42
43namespace iceberg::rest {
44
46class ICEBERG_REST_EXPORT RestCatalog final
47 : public SessionCatalog,
48 public std::enable_shared_from_this<RestCatalog> {
49 public:
50 ~RestCatalog() override;
51
52 RestCatalog(const RestCatalog&) = delete;
53 RestCatalog& operator=(const RestCatalog&) = delete;
54 RestCatalog(RestCatalog&&) = delete;
55 RestCatalog& operator=(RestCatalog&&) = delete;
56
57 using ClientFactory =
58 std::function<Result<std::shared_ptr<HttpClient>>(const RestCatalogProperties&)>;
59
72 ClientFactory client_factory = {},
73 Executor* auth_executor = nullptr,
74 Executor* metrics_executor = nullptr);
75
76 std::string_view name() const override;
77
79
81
82 private:
83 class ContextCatalog;
84 class TableScopedCatalog;
85
86 RestCatalog(RestCatalogProperties config, std::shared_ptr<FileIO> file_io,
87 std::shared_ptr<HttpClient> client, std::shared_ptr<ResourcePaths> paths,
88 std::unordered_set<Endpoint> endpoints,
89 std::unique_ptr<auth::AuthManager> auth_manager,
90 std::shared_ptr<auth::AuthSession> catalog_session,
91 SnapshotMode snapshot_mode,
92 std::optional<ScanPlanningMode> client_scan_planning_mode,
93 SessionContext default_context, std::shared_ptr<MetricsReporter> reporter,
94 Executor* metrics_executor);
95
96 Result<std::shared_ptr<auth::AuthSession>> ContextualAuthSession(
97 const SessionContext& context);
98
100 const TableIdentifier& identifier,
101 const std::unordered_map<std::string, std::string>& table_config,
102 std::shared_ptr<auth::AuthSession> contextual_session);
103
105 const SessionContext& context, const TableIdentifier& identifier,
106 const std::unordered_map<std::string, std::string>& table_config,
107 const std::vector<StorageCredential>& storage_credentials,
108 std::shared_ptr<auth::AuthSession> table_session) const;
109
113 Result<std::shared_ptr<StorageCredentialProvider>> MakeStorageCredentialProvider(
114 const TableIdentifier& identifier, std::shared_ptr<auth::AuthSession> table_session,
115 std::optional<std::string> plan_id = std::nullopt) const;
116
117 Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns,
118 auth::AuthSession& session) const;
119
120 Status CreateNamespace(const Namespace& ns,
121 const std::unordered_map<std::string, std::string>& properties,
122 auth::AuthSession& session);
123
125 const Namespace& ns, auth::AuthSession& session) const;
126
127 Status DropNamespace(const Namespace& ns, auth::AuthSession& session);
128
129 Result<bool> NamespaceExists(const Namespace& ns, auth::AuthSession& session) const;
130
131 Status UpdateNamespaceProperties(
132 const Namespace& ns, const std::unordered_map<std::string, std::string>& updates,
133 const std::unordered_set<std::string>& removals, auth::AuthSession& session);
134
136 auth::AuthSession& session) const;
137
139 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
140 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
141 const std::string& location,
142 const std::unordered_map<std::string, std::string>& properties,
143 const SessionContext& context,
144 std::shared_ptr<auth::AuthSession> contextual_session);
145
147 const TableIdentifier& identifier,
148 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
149 const std::vector<std::unique_ptr<TableUpdate>>& updates,
150 const SessionContext& context,
151 std::shared_ptr<auth::AuthSession> contextual_session);
152
153 Result<std::shared_ptr<Transaction>> StageCreateTable(
154 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
155 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
156 const std::string& location,
157 const std::unordered_map<std::string, std::string>& properties,
158 const SessionContext& context,
159 std::shared_ptr<auth::AuthSession> contextual_session);
160
161 Result<bool> TableExists(const TableIdentifier& identifier,
162 auth::AuthSession& session) const;
163
164 Status RenameTable(const TableIdentifier& from, const TableIdentifier& to,
165 auth::AuthSession& session);
166
167 Status DropTable(const TableIdentifier& identifier, bool purge,
168 auth::AuthSession& session);
169
171 const TableIdentifier& identifier, const SessionContext& context,
172 std::shared_ptr<auth::AuthSession> request_session,
173 std::shared_ptr<auth::AuthSession> contextual_session);
174
175 Result<std::shared_ptr<Table>> RegisterTable(
176 const TableIdentifier& identifier, const std::string& metadata_file_location,
177 const SessionContext& context,
178 std::shared_ptr<auth::AuthSession> contextual_session);
179
180 Result<LoadTableResult> LoadTableInternal(const TableIdentifier& identifier,
181 auth::AuthSession& session) const;
182
191 const TableIdentifier& identifier,
192 const std::shared_ptr<auth::AuthSession>& table_session) const;
193
194 Result<LoadTableResult> CreateTableInternal(
195 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
196 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
197 const std::string& location,
198 const std::unordered_map<std::string, std::string>& properties, bool stage_create,
199 auth::AuthSession& session);
200
201 Result<CommitTableResponse> UpdateTableInternal(
202 const TableIdentifier& identifier,
203 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
204 const std::vector<std::unique_ptr<TableUpdate>>& updates,
205 auth::AuthSession& session);
206
207 Result<std::shared_ptr<Table>> MakeTableFromLoadResult(
208 const TableIdentifier& identifier, LoadTableResult result,
209 const SessionContext& context,
210 std::shared_ptr<auth::AuthSession> contextual_session);
211
212 Result<std::shared_ptr<Table>> MakeTableFromCommitResponse(
213 const TableIdentifier& identifier, CommitTableResponse response,
214 const SessionContext& context,
215 const std::unordered_map<std::string, std::string>& table_config,
216 std::shared_ptr<auth::AuthSession> table_session, std::shared_ptr<FileIO> table_io);
217
220 const TableIdentifier& identifier, std::shared_ptr<TableMetadata> metadata,
221 std::string metadata_location, std::shared_ptr<FileIO> table_io,
222 std::shared_ptr<Catalog> table_catalog, std::shared_ptr<MetricsReporter> reporter,
223 const std::unordered_map<std::string, std::string>& table_config,
224 std::shared_ptr<auth::AuthSession> table_session,
225 std::unique_ptr<Labels> labels = nullptr);
226
227 RestCatalogProperties config_;
228 std::shared_ptr<FileIO> file_io_;
229 std::shared_ptr<HttpClient> client_;
230 std::shared_ptr<ResourcePaths> paths_;
231 std::string name_;
232 std::unordered_set<Endpoint> supported_endpoints_;
233 std::unique_ptr<auth::AuthManager> auth_manager_;
234 std::shared_ptr<auth::AuthSession> catalog_session_;
235 SnapshotMode snapshot_mode_;
236 std::optional<ScanPlanningMode> client_scan_planning_mode_;
237 SessionContext default_context_;
238 std::weak_ptr<Catalog> default_catalog_;
239 std::shared_ptr<MetricsReporter> reporter_;
240 Executor* metrics_executor_ = nullptr;
241};
242
243} // namespace iceberg::rest
Define the catalog API for table and namespace operations.
RestCatalogProperties implementation for Iceberg REST API.
Schedules iceberg-cpp tasks.
Definition executor.h:46
Factory interface for creating context-bound catalog views.
Definition session_catalog.h:44
Definition expected.h:1199
Configuration class for a REST Catalog.
Definition catalog_properties.h:43
Session-aware REST catalog root.
Definition rest_catalog.h:48
Result< std::shared_ptr< Catalog > > WithContext(SessionContext context) override
Return a Catalog view bound to the supplied session context.
std::string_view name() const override
Catalog name.
Result< std::shared_ptr< Catalog > > AsCatalog() override
Return a Catalog view bound to the catalog's default session.
static Result< std::shared_ptr< RestCatalog > > Make(const RestCatalogProperties &config, ClientFactory client_factory={}, Executor *auth_executor=nullptr, Executor *metrics_executor=nullptr)
Create a RestCatalog instance.
An authentication session that can authenticate outgoing HTTP requests.
Definition auth_session.h:50
Define symbol visibility macros for the REST catalog library.
Catalog-provided labels for tables and their fields.
REST catalog APIs.
Definition auth_manager.h:34
SnapshotMode
Snapshot loading mode for REST catalog.
Definition catalog_properties.h:36
Define Result, Status, and error helpers.
Define session catalog routing APIs.
Define session context metadata.
Define storage credential metadata.
A namespace in a catalog.
Definition table_identifier.h:35
Session state used to bind catalog operations to a caller context.
Definition session_context.h:42
Identifies a table in iceberg catalog.
Definition table_identifier.h:46
Response from committing changes to a table.
Definition types.h:299
Result body for table create/load/register APIs.
Definition types.h:186