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/result.h"
32
35
36namespace iceberg::rest {
37
39class ICEBERG_REST_EXPORT RestCatalog : public Catalog,
40 public std::enable_shared_from_this<RestCatalog> {
41 public:
42 ~RestCatalog() override;
43
44 RestCatalog(const RestCatalog&) = delete;
45 RestCatalog& operator=(const RestCatalog&) = delete;
46 RestCatalog(RestCatalog&&) = delete;
47 RestCatalog& operator=(RestCatalog&&) = delete;
48
50 static Result<std::shared_ptr<RestCatalog>> Make(const RestCatalogProperties& config);
51
52 std::string_view name() const override;
53
54 Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const override;
55
56 Status CreateNamespace(
57 const Namespace& ns,
58 const std::unordered_map<std::string, std::string>& properties) override;
59
60 Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
61 const Namespace& ns) const override;
62
63 Status DropNamespace(const Namespace& ns) override;
64
65 Result<bool> NamespaceExists(const Namespace& ns) const override;
66
67 Status UpdateNamespaceProperties(
68 const Namespace& ns, const std::unordered_map<std::string, std::string>& updates,
69 const std::unordered_set<std::string>& removals) override;
70
71 Result<std::vector<TableIdentifier>> ListTables(const Namespace& ns) const override;
72
73 Result<std::shared_ptr<Table>> CreateTable(
74 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
75 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
76 const std::string& location,
77 const std::unordered_map<std::string, std::string>& properties) override;
78
79 Result<std::shared_ptr<Table>> UpdateTable(
80 const TableIdentifier& identifier,
81 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
82 const std::vector<std::unique_ptr<TableUpdate>>& updates) override;
83
84 Result<std::shared_ptr<Transaction>> StageCreateTable(
85 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
86 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
87 const std::string& location,
88 const std::unordered_map<std::string, std::string>& properties) override;
89
90 Result<bool> TableExists(const TableIdentifier& identifier) const override;
91
92 Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) override;
93
94 Status DropTable(const TableIdentifier& identifier, bool purge) override;
95
96 Result<std::shared_ptr<Table>> LoadTable(const TableIdentifier& identifier) override;
97
98 Result<std::shared_ptr<Table>> RegisterTable(
99 const TableIdentifier& identifier,
100 const std::string& metadata_file_location) override;
101
102 private:
103 RestCatalog(RestCatalogProperties config, std::shared_ptr<FileIO> file_io,
104 std::unique_ptr<HttpClient> client, std::unique_ptr<ResourcePaths> paths,
105 std::unordered_set<Endpoint> endpoints,
106 std::unique_ptr<auth::AuthManager> auth_manager,
107 std::shared_ptr<auth::AuthSession> catalog_session,
108 SnapshotMode snapshot_mode);
109
110 Result<std::string> LoadTableInternal(const TableIdentifier& identifier) const;
111
112 Result<LoadTableResult> CreateTableInternal(
113 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
114 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
115 const std::string& location,
116 const std::unordered_map<std::string, std::string>& properties, bool stage_create);
117
118 RestCatalogProperties config_;
119 std::shared_ptr<FileIO> file_io_;
120 std::unique_ptr<HttpClient> client_;
121 std::unique_ptr<ResourcePaths> paths_;
122 std::string name_;
123 std::unordered_set<Endpoint> supported_endpoints_;
124 std::unique_ptr<auth::AuthManager> auth_manager_;
125 std::shared_ptr<auth::AuthSession> catalog_session_;
126 SnapshotMode snapshot_mode_;
127};
128
129} // namespace iceberg::rest
RestCatalogProperties implementation for Iceberg REST API.
SnapshotMode
Snapshot loading mode for REST catalog.
Definition catalog_properties.h:35
A Catalog API for table create, drop, and load operations.
Definition catalog.h:39
Configuration class for a REST Catalog.
Definition catalog_properties.h:39
Rest catalog implementation.
Definition rest_catalog.h:40
A namespace in a catalog.
Definition table_identifier.h:35
Identifies a table in iceberg catalog.
Definition table_identifier.h:46