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"
29#include "iceberg/catalog/rest/iceberg_rest_export.h"
31#include "iceberg/catalog/session_catalog.h"
32#include "iceberg/catalog/session_context.h"
33#include "iceberg/result.h"
34#include "iceberg/storage_credential.h"
35
38
39namespace iceberg::rest {
40
42class ICEBERG_REST_EXPORT RestCatalog final
43 : public SessionCatalog,
44 public std::enable_shared_from_this<RestCatalog> {
45 public:
46 ~RestCatalog() override;
47
48 RestCatalog(const RestCatalog&) = delete;
49 RestCatalog& operator=(const RestCatalog&) = delete;
50 RestCatalog(RestCatalog&&) = delete;
51 RestCatalog& operator=(RestCatalog&&) = delete;
52
54 static Result<std::shared_ptr<RestCatalog>> Make(const RestCatalogProperties& config);
55
56 std::string_view name() const override;
57
58 Result<std::shared_ptr<Catalog>> AsCatalog() override;
59
60 Result<std::shared_ptr<Catalog>> WithContext(SessionContext context) override;
61
62 private:
63 class ContextCatalog;
65
66 RestCatalog(RestCatalogProperties config, std::shared_ptr<FileIO> file_io,
67 std::unique_ptr<HttpClient> client, std::unique_ptr<ResourcePaths> paths,
68 std::unordered_set<Endpoint> endpoints,
69 std::unique_ptr<auth::AuthManager> auth_manager,
70 std::shared_ptr<auth::AuthSession> catalog_session,
71 SnapshotMode snapshot_mode, SessionContext default_context);
72
73 Result<std::shared_ptr<auth::AuthSession>> ContextualAuthSession(
74 const SessionContext& context);
75
76 Result<std::shared_ptr<auth::AuthSession>> TableAuthSession(
77 const TableIdentifier& identifier,
78 const std::unordered_map<std::string, std::string>& table_config,
79 std::shared_ptr<auth::AuthSession> contextual_session);
80
81 Result<std::shared_ptr<FileIO>> TableFileIO(
82 const SessionContext& context,
83 const std::unordered_map<std::string, std::string>& table_config,
84 const std::vector<StorageCredential>& storage_credentials) const;
85
86 Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns,
87 auth::AuthSession& session) const;
88
89 Status CreateNamespace(const Namespace& ns,
90 const std::unordered_map<std::string, std::string>& properties,
91 auth::AuthSession& session);
92
93 Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
94 const Namespace& ns, auth::AuthSession& session) const;
95
96 Status DropNamespace(const Namespace& ns, auth::AuthSession& session);
97
98 Result<bool> NamespaceExists(const Namespace& ns, auth::AuthSession& session) const;
99
100 Status UpdateNamespaceProperties(
101 const Namespace& ns, const std::unordered_map<std::string, std::string>& updates,
102 const std::unordered_set<std::string>& removals, auth::AuthSession& session);
103
104 Result<std::vector<TableIdentifier>> ListTables(const Namespace& ns,
105 auth::AuthSession& session) const;
106
107 Result<std::shared_ptr<Table>> CreateTable(
108 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
109 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
110 const std::string& location,
111 const std::unordered_map<std::string, std::string>& properties,
112 const SessionContext& context,
113 std::shared_ptr<auth::AuthSession> contextual_session);
114
115 Result<std::shared_ptr<Table>> UpdateTable(
116 const TableIdentifier& identifier,
117 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
118 const std::vector<std::unique_ptr<TableUpdate>>& updates,
119 const SessionContext& context,
120 std::shared_ptr<auth::AuthSession> contextual_session);
121
122 Result<std::shared_ptr<Transaction>> StageCreateTable(
123 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
124 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
125 const std::string& location,
126 const std::unordered_map<std::string, std::string>& properties,
127 const SessionContext& context,
128 std::shared_ptr<auth::AuthSession> contextual_session);
129
130 Result<bool> TableExists(const TableIdentifier& identifier,
131 auth::AuthSession& session) const;
132
133 Status RenameTable(const TableIdentifier& from, const TableIdentifier& to,
134 auth::AuthSession& session);
135
136 Status DropTable(const TableIdentifier& identifier, bool purge,
137 auth::AuthSession& session);
138
139 Result<std::shared_ptr<Table>> LoadTable(
140 const TableIdentifier& identifier, const SessionContext& context,
141 std::shared_ptr<auth::AuthSession> request_session,
142 std::shared_ptr<auth::AuthSession> contextual_session);
143
144 Result<std::shared_ptr<Table>> RegisterTable(
145 const TableIdentifier& identifier, const std::string& metadata_file_location,
146 const SessionContext& context,
147 std::shared_ptr<auth::AuthSession> contextual_session);
148
149 Result<LoadTableResult> LoadTableInternal(const TableIdentifier& identifier,
150 auth::AuthSession& session) const;
151
152 Result<LoadTableResult> CreateTableInternal(
153 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
154 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
155 const std::string& location,
156 const std::unordered_map<std::string, std::string>& properties, bool stage_create,
157 auth::AuthSession& session);
158
159 Result<CommitTableResponse> UpdateTableInternal(
160 const TableIdentifier& identifier,
161 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
162 const std::vector<std::unique_ptr<TableUpdate>>& updates,
163 auth::AuthSession& session);
164
165 Result<std::shared_ptr<Table>> MakeTableFromLoadResult(
166 const TableIdentifier& identifier, LoadTableResult result,
167 const SessionContext& context,
168 std::shared_ptr<auth::AuthSession> contextual_session);
169
170 Result<std::shared_ptr<Table>> MakeTableFromCommitResponse(
171 const TableIdentifier& identifier, CommitTableResponse response,
172 const SessionContext& context,
173 const std::unordered_map<std::string, std::string>& table_config,
174 std::shared_ptr<auth::AuthSession> table_session, std::shared_ptr<FileIO> table_io);
175
176 RestCatalogProperties config_;
177 std::shared_ptr<FileIO> file_io_;
178 std::unique_ptr<HttpClient> client_;
179 std::unique_ptr<ResourcePaths> paths_;
180 std::string name_;
181 std::unordered_set<Endpoint> supported_endpoints_;
182 std::unique_ptr<auth::AuthManager> auth_manager_;
183 std::shared_ptr<auth::AuthSession> catalog_session_;
184 SnapshotMode snapshot_mode_;
185 SessionContext default_context_;
186 std::weak_ptr<Catalog> default_catalog_;
187};
188
189} // namespace iceberg::rest
RestCatalogProperties implementation for Iceberg REST API.
SnapshotMode
Snapshot loading mode for REST catalog.
Definition catalog_properties.h:35
Factory interface for creating context-bound catalog views.
Definition session_catalog.h:41
Configuration class for a REST Catalog.
Definition catalog_properties.h:39
Definition rest_catalog.cc:137
Session-aware REST catalog root.
Definition rest_catalog.h:44
An authentication session that can authenticate outgoing HTTP requests.
Definition auth_session.h:37
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:39
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