iceberg-cpp
Loading...
Searching...
No Matches
in_memory_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
24
25#include <memory>
26#include <shared_mutex>
27
28#include "iceberg/catalog.h"
29
30namespace iceberg {
31
42class ICEBERG_EXPORT InMemoryCatalog
43 : public Catalog,
44 public std::enable_shared_from_this<InMemoryCatalog> {
45 public:
46 InMemoryCatalog(std::string name, std::shared_ptr<FileIO> file_io,
47 std::string warehouse_location,
48 std::unordered_map<std::string, std::string> properties,
49 std::shared_ptr<MetricsReporter> reporter = nullptr);
50 ~InMemoryCatalog() override;
51
53 std::string const& name, std::shared_ptr<FileIO> const& file_io,
54 std::string const& warehouse_location,
55 std::unordered_map<std::string, std::string> const& properties);
56
57 std::string_view name() const override;
58
60 const Namespace& ns,
61 const std::unordered_map<std::string, std::string>& properties) override;
62
64
65 Status DropNamespace(const Namespace& ns) override;
66
67 Result<bool> NamespaceExists(const Namespace& ns) const override;
68
70 const Namespace& ns) const override;
71
73 const Namespace& ns, const std::unordered_map<std::string, std::string>& updates,
74 const std::unordered_set<std::string>& removals) override;
75
77
79 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
80 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
81 const std::string& location,
82 const std::unordered_map<std::string, std::string>& properties) override;
83
85 const TableIdentifier& identifier,
86 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
87 const std::vector<std::unique_ptr<TableUpdate>>& updates) override;
88
90 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
91 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
92 const std::string& location,
93 const std::unordered_map<std::string, std::string>& properties) override;
94
95 Result<bool> TableExists(const TableIdentifier& identifier) const override;
96
97 Status DropTable(const TableIdentifier& identifier, bool purge) override;
98
99 Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) override;
100
102
104 const TableIdentifier& identifier,
105 const std::string& metadata_file_location) override;
106
107 private:
108 std::string catalog_name_;
109 std::unordered_map<std::string, std::string> properties_;
110 std::shared_ptr<FileIO> file_io_;
111 std::string warehouse_location_;
112 std::unique_ptr<class InMemoryNamespace> root_namespace_;
113 mutable std::shared_mutex mutex_;
114 std::shared_ptr<MetricsReporter> reporter_;
115};
116
117} // namespace iceberg
Define the catalog API for table and namespace operations.
A Catalog API for table create, drop, and load operations.
Definition catalog.h:42
An in-memory implementation of the Iceberg Catalog interface.
Definition in_memory_catalog.h:44
Result< std::shared_ptr< Table > > LoadTable(const TableIdentifier &identifier) override
Load a table.
Result< std::unordered_map< std::string, std::string > > GetNamespaceProperties(const Namespace &ns) const override
Get metadata properties for a namespace.
std::string_view name() const override
Return the name for this catalog.
Result< bool > TableExists(const TableIdentifier &identifier) const override
Check whether table exists.
Result< std::vector< Namespace > > ListNamespaces(const Namespace &ns) const override
List child namespaces from the given namespace.
Status UpdateNamespaceProperties(const Namespace &ns, const std::unordered_map< std::string, std::string > &updates, const std::unordered_set< std::string > &removals) override
Update a namespace's properties by applying additions and removals.
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
Update a table.
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
Create a table.
Status RenameTable(const TableIdentifier &from, const TableIdentifier &to) override
Rename a table.
Status DropTable(const TableIdentifier &identifier, bool purge) override
Drop a table; optionally delete data and metadata files.
Status CreateNamespace(const Namespace &ns, const std::unordered_map< std::string, std::string > &properties) override
Create a namespace with associated properties.
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
Start a transaction to create a table.
Result< std::shared_ptr< Table > > RegisterTable(const TableIdentifier &identifier, const std::string &metadata_file_location) override
Register a table with the catalog if it does not exist.
Result< bool > NamespaceExists(const Namespace &ns) const override
Check whether the namespace exists.
Status DropNamespace(const Namespace &ns) override
Drop a namespace.
Result< std::vector< TableIdentifier > > ListTables(const Namespace &ns) const override
Return all the identifiers under this namespace.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
A namespace in a catalog.
Definition table_identifier.h:35
Identifies a table in iceberg catalog.
Definition table_identifier.h:46