iceberg-cpp
Loading...
Searching...
No Matches
in_memory_catalog.h
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 <shared_mutex>
23
24#include "iceberg/catalog.h"
25
26namespace iceberg {
27
38class ICEBERG_EXPORT InMemoryCatalog
39 : public Catalog,
40 public std::enable_shared_from_this<InMemoryCatalog> {
41 public:
42 InMemoryCatalog(std::string const& name, std::shared_ptr<FileIO> const& file_io,
43 std::string const& warehouse_location,
44 std::unordered_map<std::string, std::string> const& properties);
45 ~InMemoryCatalog() override;
46
47 static std::shared_ptr<InMemoryCatalog> Make(
48 std::string const& name, std::shared_ptr<FileIO> const& file_io,
49 std::string const& warehouse_location,
50 std::unordered_map<std::string, std::string> const& properties);
51
52 std::string_view name() const override;
53
54 Status CreateNamespace(
55 const Namespace& ns,
56 const std::unordered_map<std::string, std::string>& properties) override;
57
58 Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const override;
59
60 Status DropNamespace(const Namespace& ns) override;
61
62 Result<bool> NamespaceExists(const Namespace& ns) const override;
63
64 Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
65 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 DropTable(const TableIdentifier& identifier, bool purge) override;
93
94 Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) 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 std::string catalog_name_;
104 std::unordered_map<std::string, std::string> properties_;
105 std::shared_ptr<FileIO> file_io_;
106 std::string warehouse_location_;
107 std::unique_ptr<class InMemoryNamespace> root_namespace_;
108 mutable std::shared_mutex mutex_;
109};
110
111} // namespace iceberg
A Catalog API for table create, drop, and load operations.
Definition catalog.h:39
An in-memory implementation of the Iceberg Catalog interface.
Definition in_memory_catalog.h:40
A namespace in a catalog.
Definition table_identifier.h:35
Identifies a table in iceberg catalog.
Definition table_identifier.h:46