Kùzu C++ API
Loading...
Searching...
No Matches
catalog.h
Go to the documentation of this file.
1#pragma once
2
4#include "catalog_set.h"
5#include "cast.h"
6#include "function.h"
7
8namespace kuzu::main {
9struct DBConfig;
10} // namespace kuzu::main
11
12namespace kuzu {
13namespace main {
14class AttachedKuzuDatabase;
15} // namespace main
16
17namespace binder {
18struct BoundAlterInfo;
19struct BoundCreateTableInfo;
20struct BoundCreateSequenceInfo;
21} // namespace binder
22
23namespace common {
24class VirtualFileSystem;
25} // namespace common
26
27namespace function {
28struct ScalarMacroFunction;
29} // namespace function
30
31namespace storage {
32class WAL;
33} // namespace storage
34
35namespace transaction {
36class Transaction;
37} // namespace transaction
38
39namespace catalog {
41class NodeTableCatalogEntry;
42class RelTableCatalogEntry;
43class RelGroupCatalogEntry;
44class RDFGraphCatalogEntry;
46class SequenceCatalogEntry;
47
49 friend class main::AttachedKuzuDatabase;
50
51public:
52 // This is extended by DuckCatalog and PostgresCatalog.
54 Catalog(const std::string& directory, common::VirtualFileSystem* vfs);
55 virtual ~Catalog() = default;
56
57 // ----------------------------- Table Schemas ----------------------------
58 bool containsTable(transaction::Transaction* transaction, const std::string& tableName) const;
59
61 const std::string& tableName) const;
62 std::vector<common::table_id_t> getNodeTableIDs(transaction::Transaction* transaction) const;
63 std::vector<common::table_id_t> getRelTableIDs(transaction::Transaction* transaction) const;
64
65 // TODO: Should remove this.
66 std::string getTableName(transaction::Transaction* transaction,
67 common::table_id_t tableID) const;
69 const std::string& tableName) const;
71 common::table_id_t tableID) const;
72 std::vector<NodeTableCatalogEntry*> getNodeTableEntries(
73 transaction::Transaction* transaction) const;
74 std::vector<RelTableCatalogEntry*> getRelTableEntries(
75 transaction::Transaction* transaction) const;
76 std::vector<RelGroupCatalogEntry*> getRelTableGroupEntries(
77 transaction::Transaction* transaction) const;
78 std::vector<RDFGraphCatalogEntry*> getRdfGraphEntries(
79 transaction::Transaction* transaction) const;
80 std::vector<TableCatalogEntry*> getTableEntries(transaction::Transaction* transaction) const;
81 std::vector<TableCatalogEntry*> getTableEntries(transaction::Transaction* transaction,
82 const common::table_id_vector_t& tableIDs) const;
86 common::table_id_t nodeTableID) const;
88 common::table_id_t nodeTableID) const;
89
92 void dropTableEntry(transaction::Transaction* transaction, std::string name);
95
96 // ----------------------------- Sequences ----------------------------
98 const std::string& sequenceName) const;
99
101 const std::string& sequenceName) const;
102 SequenceCatalogEntry* getSequenceCatalogEntry(transaction::Transaction* transaction,
103 common::sequence_id_t sequenceID) const;
104 std::vector<SequenceCatalogEntry*> getSequenceEntries(
105 transaction::Transaction* transaction) const;
106
108 const binder::BoundCreateSequenceInfo& info);
109 void dropSequence(transaction::Transaction* transaction, std::string name);
111
112 static std::string genSerialName(const std::string& tableName, const std::string& propertyName);
113
114 // ----------------------------- Types ----------------------------
115 void createType(transaction::Transaction* transaction, std::string name,
118 bool containsType(transaction::Transaction* transaction, const std::string& typeName);
119
120 // ----------------------------- Functions ----------------------------
122 std::string name, function::function_set functionSet);
123 void dropFunction(transaction::Transaction* transaction, const std::string& name);
124 void addBuiltInFunction(CatalogEntryType entryType, std::string name,
125 function::function_set functionSet);
127 CatalogEntry* getFunctionEntry(transaction::Transaction* transaction, const std::string& name);
128 std::vector<FunctionCatalogEntry*> getFunctionEntries(
129 transaction::Transaction* transaction) const;
130
131 bool containsMacro(transaction::Transaction* transaction, const std::string& macroName) const;
132 void addScalarMacroFunction(transaction::Transaction* transaction, std::string name,
133 std::unique_ptr<function::ScalarMacroFunction> macro);
134 function::ScalarMacroFunction* getScalarMacroFunction(transaction::Transaction* transaction,
135 const std::string& name) const;
136 std::vector<std::string> getMacroNames(transaction::Transaction* transaction) const;
137
138 void checkpoint(const std::string& databasePath, common::VirtualFileSystem* fs) const;
139
140 template<class TARGET>
141 TARGET* ptrCast() {
142 return common::ku_dynamic_cast<Catalog*, TARGET*>(this);
143 }
144
145private:
146 // The clientContext needs to be used when reading from a remote filesystem which
147 // requires some user-specific configs (e.g. s3 username, password).
148 void readFromFile(const std::string& directory, common::VirtualFileSystem* fs,
149 common::FileVersionType versionType, main::ClientContext* context = nullptr);
150 void saveToFile(const std::string& directory, common::VirtualFileSystem* fs,
151 common::FileVersionType versionType) const;
152
153private:
154 // ----------------------------- Functions ----------------------------
155 void registerBuiltInFunctions();
156
157 // ----------------------------- Table entries ----------------------------
158
159 void iterateCatalogEntries(transaction::Transaction* transaction,
160 std::function<void(CatalogEntry*)> func) const {
161 for (auto& [_, entry] : tables->getEntries(transaction)) {
162 func(entry);
163 }
164 }
165 template<typename T>
166 std::vector<T*> getTableCatalogEntries(transaction::Transaction* transaction,
167 CatalogEntryType catalogType) const {
168 std::vector<T*> result;
169 iterateCatalogEntries(transaction, [&](CatalogEntry* entry) {
170 if (entry->getType() == catalogType) {
171 result.push_back(common::ku_dynamic_cast<CatalogEntry*, T*>(entry));
172 }
173 });
174 return result;
175 }
176
177 std::vector<common::table_id_t> getTableIDs(transaction::Transaction* transaction,
178 CatalogEntryType catalogType) const;
179
180 void alterRdfChildTableEntries(transaction::Transaction* transaction, CatalogEntry* entry,
181 const binder::BoundAlterInfo& info) const;
182 std::unique_ptr<CatalogEntry> createNodeTableEntry(transaction::Transaction* transaction,
183 common::table_id_t tableID, const binder::BoundCreateTableInfo& info) const;
184 std::unique_ptr<CatalogEntry> createRelTableEntry(transaction::Transaction* transaction,
185 common::table_id_t tableID, const binder::BoundCreateTableInfo& info) const;
186 std::unique_ptr<CatalogEntry> createRelTableGroupEntry(transaction::Transaction* transaction,
187 common::table_id_t tableID, const binder::BoundCreateTableInfo& info);
188 std::unique_ptr<CatalogEntry> createRdfGraphEntry(transaction::Transaction* transaction,
189 common::table_id_t tableID, const binder::BoundCreateTableInfo& info);
190
191 // ----------------------------- Sequence entries ----------------------------
192 void iterateSequenceCatalogEntries(transaction::Transaction* transaction,
193 std::function<void(CatalogEntry*)> func) const {
194 for (auto& [_, entry] : sequences->getEntries(transaction)) {
195 func(entry);
196 }
197 }
198
199protected:
200 std::unique_ptr<CatalogSet> tables;
201
202private:
203 std::unique_ptr<CatalogSet> sequences;
204 std::unique_ptr<CatalogSet> functions;
205 std::unique_ptr<CatalogSet> types;
206};
207
208} // namespace catalog
209} // namespace kuzu
#define KUZU_API
Definition api.h:25
Definition catalog_entry.h:18
Definition catalog.h:48
static std::string genSerialName(const std::string &tableName, const std::string &propertyName)
TableCatalogEntry * getTableCatalogEntry(transaction::Transaction *transaction, common::table_id_t tableID) const
CatalogEntry * getFunctionEntry(transaction::Transaction *transaction, const std::string &name)
std::vector< common::table_id_t > getNodeTableIDs(transaction::Transaction *transaction) const
std::vector< common::table_id_t > getRelTableIDs(transaction::Transaction *transaction) const
common::table_id_set_t getFwdRelTableIDs(transaction::Transaction *transaction, common::table_id_t nodeTableID) const
std::unique_ptr< CatalogSet > tables
Definition catalog.h:200
void checkpoint(const std::string &databasePath, common::VirtualFileSystem *fs) const
void dropTableEntry(transaction::Transaction *transaction, std::string name)
std::vector< SequenceCatalogEntry * > getSequenceEntries(transaction::Transaction *transaction) const
bool containsMacro(transaction::Transaction *transaction, const std::string &macroName) const
void dropSequence(transaction::Transaction *transaction, std::string name)
CatalogSet * getFunctions(transaction::Transaction *transaction) const
Catalog(const std::string &directory, common::VirtualFileSystem *vfs)
common::sequence_id_t createSequence(transaction::Transaction *transaction, const binder::BoundCreateSequenceInfo &info)
bool containsTable(transaction::Transaction *transaction, const std::string &tableName) const
void dropFunction(transaction::Transaction *transaction, const std::string &name)
void alterTableEntry(transaction::Transaction *transaction, const binder::BoundAlterInfo &info)
void createType(transaction::Transaction *transaction, std::string name, common::LogicalType type)
std::vector< FunctionCatalogEntry * > getFunctionEntries(transaction::Transaction *transaction) const
common::sequence_id_t getSequenceID(transaction::Transaction *transaction, const std::string &sequenceName) const
SequenceCatalogEntry * getSequenceCatalogEntry(transaction::Transaction *transaction, common::sequence_id_t sequenceID) const
std::vector< RelGroupCatalogEntry * > getRelTableGroupEntries(transaction::Transaction *transaction) const
std::vector< std::string > getMacroNames(transaction::Transaction *transaction) const
bool containsType(transaction::Transaction *transaction, const std::string &typeName)
void dropSequence(transaction::Transaction *transaction, common::sequence_id_t sequenceID)
std::vector< TableCatalogEntry * > getTableEntries(transaction::Transaction *transaction, const common::table_id_vector_t &tableIDs) const
common::table_id_set_t getBwdRelTableIDs(transaction::Transaction *transaction, common::table_id_t nodeTableID) const
common::table_id_t createTableSchema(transaction::Transaction *transaction, const binder::BoundCreateTableInfo &info)
bool tableInRelGroup(transaction::Transaction *transaction, common::table_id_t tableID) const
std::vector< RDFGraphCatalogEntry * > getRdfGraphEntries(transaction::Transaction *transaction) const
virtual ~Catalog()=default
void addFunction(transaction::Transaction *transaction, CatalogEntryType entryType, std::string name, function::function_set functionSet)
bool tableInRDFGraph(transaction::Transaction *transaction, common::table_id_t tableID) const
common::table_id_t getTableID(transaction::Transaction *transaction, const std::string &tableName) const
function::ScalarMacroFunction * getScalarMacroFunction(transaction::Transaction *transaction, const std::string &name) const
void addScalarMacroFunction(transaction::Transaction *transaction, std::string name, std::unique_ptr< function::ScalarMacroFunction > macro)
TARGET * ptrCast()
Definition catalog.h:141
std::string getTableName(transaction::Transaction *transaction, common::table_id_t tableID) const
void dropTableEntry(transaction::Transaction *transaction, common::table_id_t tableID)
TableCatalogEntry * getTableCatalogEntry(transaction::Transaction *transaction, const std::string &tableName) const
void addBuiltInFunction(CatalogEntryType entryType, std::string name, function::function_set functionSet)
std::vector< TableCatalogEntry * > getTableEntries(transaction::Transaction *transaction) const
std::vector< RelTableCatalogEntry * > getRelTableEntries(transaction::Transaction *transaction) const
bool containsSequence(transaction::Transaction *transaction, const std::string &sequenceName) const
common::LogicalType getType(transaction::Transaction *, std::string name)
std::vector< NodeTableCatalogEntry * > getNodeTableEntries(transaction::Transaction *transaction) const
Definition catalog_set.h:24
Definition function_catalog_entry.h:9
Definition table_catalog_entry.h:24
Definition types.h:201
Contain client side configuration. We make profiler associated per query, so profiler is not maintain...
Definition client_context.h:51
Definition transaction.h:28
CatalogEntryType
Definition catalog_entry_type.h:9
FileVersionType
Definition types.h:556
std::unordered_set< table_id_t > table_id_set_t
Definition internal_id_t.h:16
uint64_t table_id_t
Definition internal_id_t.h:14
std::vector< table_id_t > table_id_vector_t
Definition internal_id_t.h:15
uint64_t sequence_id_t
Definition types.h:55
std::vector< std::unique_ptr< Function > > function_set
Definition function.h:43
Definition bind_input.h:10
Definition alter_type.h:5
Definition bound_alter_info.h:25
Definition bound_create_table_info.h:35