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 <memory>
23#include <string>
24#include <unordered_set>
25
26#include "iceberg/catalog.h"
33#include "iceberg/result.h"
35#include "iceberg/type_fwd.h"
36
39
40namespace iceberg::rest {
41
43class ICEBERG_REST_EXPORT RestCatalog final
44 : public SessionCatalog,
45 public std::enable_shared_from_this<RestCatalog> {
46 public:
47 ~RestCatalog() override;
48
49 RestCatalog(const RestCatalog&) = delete;
50 RestCatalog& operator=(const RestCatalog&) = delete;
51 RestCatalog(RestCatalog&&) = delete;
52 RestCatalog& operator=(RestCatalog&&) = delete;
53
59 Executor* metrics_executor = nullptr);
60
61 std::string_view name() const override;
62
64
66
67 private:
68 class ContextCatalog;
69 class TableScopedCatalog;
70
71 RestCatalog(RestCatalogProperties config, std::shared_ptr<FileIO> file_io,
72 std::shared_ptr<HttpClient> client, std::unique_ptr<ResourcePaths> paths,
73 std::unordered_set<Endpoint> endpoints,
74 std::unique_ptr<auth::AuthManager> auth_manager,
75 std::shared_ptr<auth::AuthSession> catalog_session,
76 SnapshotMode snapshot_mode, SessionContext default_context,
77 std::shared_ptr<MetricsReporter> reporter, Executor* metrics_executor);
78
79 Result<std::shared_ptr<auth::AuthSession>> ContextualAuthSession(
80 const SessionContext& context);
81
83 const TableIdentifier& identifier,
84 const std::unordered_map<std::string, std::string>& table_config,
85 std::shared_ptr<auth::AuthSession> contextual_session);
86
88 const SessionContext& context,
89 const std::unordered_map<std::string, std::string>& table_config,
90 const std::vector<StorageCredential>& storage_credentials) const;
91
92 Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns,
93 auth::AuthSession& session) const;
94
95 Status CreateNamespace(const Namespace& ns,
96 const std::unordered_map<std::string, std::string>& properties,
97 auth::AuthSession& session);
98
100 const Namespace& ns, auth::AuthSession& session) const;
101
102 Status DropNamespace(const Namespace& ns, auth::AuthSession& session);
103
104 Result<bool> NamespaceExists(const Namespace& ns, auth::AuthSession& session) const;
105
106 Status UpdateNamespaceProperties(
107 const Namespace& ns, const std::unordered_map<std::string, std::string>& updates,
108 const std::unordered_set<std::string>& removals, auth::AuthSession& session);
109
111 auth::AuthSession& session) const;
112
114 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
115 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
116 const std::string& location,
117 const std::unordered_map<std::string, std::string>& properties,
118 const SessionContext& context,
119 std::shared_ptr<auth::AuthSession> contextual_session);
120
122 const TableIdentifier& identifier,
123 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
124 const std::vector<std::unique_ptr<TableUpdate>>& updates,
125 const SessionContext& context,
126 std::shared_ptr<auth::AuthSession> contextual_session);
127
128 Result<std::shared_ptr<Transaction>> StageCreateTable(
129 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
130 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
131 const std::string& location,
132 const std::unordered_map<std::string, std::string>& properties,
133 const SessionContext& context,
134 std::shared_ptr<auth::AuthSession> contextual_session);
135
136 Result<bool> TableExists(const TableIdentifier& identifier,
137 auth::AuthSession& session) const;
138
139 Status RenameTable(const TableIdentifier& from, const TableIdentifier& to,
140 auth::AuthSession& session);
141
142 Status DropTable(const TableIdentifier& identifier, bool purge,
143 auth::AuthSession& session);
144
146 const TableIdentifier& identifier, const SessionContext& context,
147 std::shared_ptr<auth::AuthSession> request_session,
148 std::shared_ptr<auth::AuthSession> contextual_session);
149
150 Result<std::shared_ptr<Table>> RegisterTable(
151 const TableIdentifier& identifier, const std::string& metadata_file_location,
152 const SessionContext& context,
153 std::shared_ptr<auth::AuthSession> contextual_session);
154
155 Result<LoadTableResult> LoadTableInternal(const TableIdentifier& identifier,
156 auth::AuthSession& session) const;
157
166 const TableIdentifier& identifier,
167 const std::shared_ptr<auth::AuthSession>& table_session) const;
168
169 Result<LoadTableResult> CreateTableInternal(
170 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
171 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
172 const std::string& location,
173 const std::unordered_map<std::string, std::string>& properties, bool stage_create,
174 auth::AuthSession& session);
175
176 Result<CommitTableResponse> UpdateTableInternal(
177 const TableIdentifier& identifier,
178 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
179 const std::vector<std::unique_ptr<TableUpdate>>& updates,
180 auth::AuthSession& session);
181
182 Result<std::shared_ptr<Table>> MakeTableFromLoadResult(
183 const TableIdentifier& identifier, LoadTableResult result,
184 const SessionContext& context,
185 std::shared_ptr<auth::AuthSession> contextual_session);
186
187 Result<std::shared_ptr<Table>> MakeTableFromCommitResponse(
188 const TableIdentifier& identifier, CommitTableResponse response,
189 const SessionContext& context,
190 const std::unordered_map<std::string, std::string>& table_config,
191 std::shared_ptr<auth::AuthSession> table_session, std::shared_ptr<FileIO> table_io);
192
193 RestCatalogProperties config_;
194 std::shared_ptr<FileIO> file_io_;
195 std::shared_ptr<HttpClient> client_;
196 std::unique_ptr<ResourcePaths> paths_;
197 std::string name_;
198 std::unordered_set<Endpoint> supported_endpoints_;
199 std::unique_ptr<auth::AuthManager> auth_manager_;
200 std::shared_ptr<auth::AuthSession> catalog_session_;
201 SnapshotMode snapshot_mode_;
202 SessionContext default_context_;
203 std::weak_ptr<Catalog> default_catalog_;
204 std::shared_ptr<MetricsReporter> reporter_;
205 Executor* metrics_executor_ = nullptr;
206};
207
208} // namespace iceberg::rest
Define the catalog API for table and namespace operations.
RestCatalogProperties implementation for Iceberg REST API.
Schedules iceberg-cpp internal planning tasks.
Definition executor.h:46
Factory interface for creating context-bound catalog views.
Definition session_catalog.h:44
Configuration class for a REST Catalog.
Definition catalog_properties.h:39
Session-aware REST catalog root.
Definition rest_catalog.h:45
static Result< std::shared_ptr< RestCatalog > > Make(const RestCatalogProperties &config, Executor *metrics_executor=nullptr)
Create a RestCatalog instance.
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.
An authentication session that can authenticate outgoing HTTP requests.
Definition auth_session.h:48
Define symbol visibility macros for the REST catalog library.
REST catalog APIs.
Definition auth_manager.h:34
SnapshotMode
Snapshot loading mode for REST catalog.
Definition catalog_properties.h:35
std::expected< T, E > Result
Result alias.
Definition result.h:88
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:281
Result body for table create/load/register APIs.
Definition types.h:185