forked from apache/iceberg-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest_catalog.h
More file actions
137 lines (107 loc) · 5.5 KB
/
Copy pathrest_catalog.h
File metadata and controls
137 lines (107 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#pragma once
#include <memory>
#include <string>
#include <unordered_set>
#include "iceberg/catalog.h"
#include "iceberg/catalog/rest/catalog_properties.h"
#include "iceberg/catalog/rest/endpoint.h"
#include "iceberg/catalog/rest/iceberg_rest_export.h"
#include "iceberg/catalog/rest/type_fwd.h"
#include "iceberg/result.h"
/// \file iceberg/catalog/rest/rest_catalog.h
/// RestCatalog implementation for Iceberg REST API.
namespace iceberg::rest {
/// \brief Rest catalog implementation.
class ICEBERG_REST_EXPORT RestCatalog : public Catalog,
public std::enable_shared_from_this<RestCatalog> {
public:
~RestCatalog() override;
RestCatalog(const RestCatalog&) = delete;
RestCatalog& operator=(const RestCatalog&) = delete;
RestCatalog(RestCatalog&&) = delete;
RestCatalog& operator=(RestCatalog&&) = delete;
/// \brief Create a RestCatalog instance.
static Result<std::shared_ptr<RestCatalog>> Make(const RestCatalogProperties& config);
std::string_view name() const override;
Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const override;
Status CreateNamespace(
const Namespace& ns,
const std::unordered_map<std::string, std::string>& properties) override;
Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
const Namespace& ns) const override;
Status DropNamespace(const Namespace& ns) override;
Result<bool> NamespaceExists(const Namespace& ns) const override;
Status UpdateNamespaceProperties(
const Namespace& ns, const std::unordered_map<std::string, std::string>& updates,
const std::unordered_set<std::string>& removals) override;
Result<std::vector<TableIdentifier>> ListTables(const Namespace& ns) const override;
Result<std::shared_ptr<Table>> CreateTable(
const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
const std::string& location,
const std::unordered_map<std::string, std::string>& properties) override;
Result<std::shared_ptr<Table>> UpdateTable(
const TableIdentifier& identifier,
const std::vector<std::unique_ptr<TableRequirement>>& requirements,
const std::vector<std::unique_ptr<TableUpdate>>& updates) override;
Result<std::shared_ptr<Transaction>> StageCreateTable(
const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
const std::string& location,
const std::unordered_map<std::string, std::string>& properties) override;
Result<bool> TableExists(const TableIdentifier& identifier) const override;
Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) override;
Status DropTable(const TableIdentifier& identifier, bool purge) override;
Result<std::shared_ptr<Table>> LoadTable(const TableIdentifier& identifier) override;
Result<std::shared_ptr<Table>> RegisterTable(
const TableIdentifier& identifier,
const std::string& metadata_file_location) override;
/// \brief Submit a table scan plan payload to the catalog scan-planning endpoint.
///
/// \param identifier a table identifier
/// \param payload serialized JSON payload for scan planning
/// \return the raw response body returned by the catalog service
Result<std::string> SubmitTableScanPlan(const TableIdentifier& identifier,
const std::string& payload);
private:
RestCatalog(RestCatalogProperties config, std::shared_ptr<FileIO> file_io,
std::unique_ptr<HttpClient> client, std::unique_ptr<ResourcePaths> paths,
std::unordered_set<Endpoint> endpoints,
std::unique_ptr<auth::AuthManager> auth_manager,
std::shared_ptr<auth::AuthSession> catalog_session,
SnapshotMode snapshot_mode);
Result<std::string> LoadTableInternal(const TableIdentifier& identifier) const;
Result<LoadTableResult> CreateTableInternal(
const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
const std::string& location,
const std::unordered_map<std::string, std::string>& properties, bool stage_create);
RestCatalogProperties config_;
std::shared_ptr<FileIO> file_io_;
std::unique_ptr<HttpClient> client_;
std::unique_ptr<ResourcePaths> paths_;
std::string name_;
std::unordered_set<Endpoint> supported_endpoints_;
std::unique_ptr<auth::AuthManager> auth_manager_;
std::shared_ptr<auth::AuthSession> catalog_session_;
SnapshotMode snapshot_mode_;
};
} // namespace iceberg::rest