Kùzu C++ API
Loading...
Searching...
No Matches
table.h
Go to the documentation of this file.
1#pragma once
2
5#include "mask.h"
6#include "column_predicate.h"
7#include "column.h"
8#include "node_group.h"
9
10namespace kuzu {
11namespace evaluator {
12class ExpressionEvaluator;
13} // namespace evaluator
14namespace storage {
15
16enum class TableScanSource : uint8_t { COMMITTED = 0, UNCOMMITTED = 1, NONE = 3 };
17
19 std::unique_ptr<common::ValueVector> rowIdxVector;
20 // Node/Rel ID vector. We assume all output vectors are within the same DataChunk as this one.
22 std::vector<common::ValueVector*> outputVectors;
23 std::vector<common::column_id_t> columnIDs;
25
26 // Only used when scan from persistent data.
27 std::vector<Column*> columns;
28
31 NodeGroup* nodeGroup = nullptr;
32 std::unique_ptr<NodeGroupScanState> nodeGroupScanState;
33
34 std::vector<ColumnPredicateSet> columnPredicateSets;
36
37 explicit TableScanState(std::vector<common::column_id_t> columnIDs)
38 : IDVector(nullptr), columnIDs{std::move(columnIDs)}, semiMask{nullptr} {
39 rowIdxVector = std::make_unique<common::ValueVector>(common::LogicalType::INT64());
40 }
41 TableScanState(std::vector<common::column_id_t> columnIDs, std::vector<Column*> columns,
42 std::vector<ColumnPredicateSet> columnPredicateSets)
43 : IDVector(nullptr), columnIDs{std::move(columnIDs)}, semiMask{nullptr},
45 rowIdxVector = std::make_unique<common::ValueVector>(common::LogicalType::INT64());
46 }
47 explicit TableScanState(std::vector<common::column_id_t> columnIDs,
48 std::vector<Column*> columns)
49 : IDVector(nullptr), columnIDs{std::move(columnIDs)}, semiMask{nullptr},
50 columns{std::move(columns)} {
51 rowIdxVector = std::make_unique<common::ValueVector>(common::LogicalType::INT64());
52 }
53 virtual ~TableScanState() = default;
55
63
64 template<class TARGET>
65 TARGET& cast() {
67 }
68 template<class TARGETT>
69 const TARGETT& cast() const {
71 }
72};
73
75 const std::vector<common::ValueVector*>& propertyVectors;
76
77 explicit TableInsertState(const std::vector<common::ValueVector*>& propertyVectors)
79 virtual ~TableInsertState() = default;
80
81 template<typename T>
85 template<typename T>
89};
90
108
110 virtual ~TableDeleteState() = default;
111
112 template<typename T>
116 template<typename T>
120};
121
124 evaluator::ExpressionEvaluator& defaultEvaluator;
125
130};
131
132class LocalTable;
133class StorageManager;
134class Table {
135public:
136 Table(const catalog::TableCatalogEntry* tableEntry, StorageManager* storageManager,
137 MemoryManager* memoryManager);
138 virtual ~Table() = default;
139
140 static std::unique_ptr<Table> loadTable(common::Deserializer& deSer,
141 const catalog::Catalog& catalog, StorageManager* storageManager,
142 MemoryManager* memoryManager, common::VirtualFileSystem* vfs, main::ClientContext* context);
143
146 std::string getTableName() const { return tableName; }
147 BMFileHandle* getDataFH() const { return dataFH; }
148
150 TableScanState& readState) = 0;
151 bool scan(transaction::Transaction* transaction, TableScanState& scanState) {
152 for (const auto& vector : scanState.outputVectors) {
153 vector->resetAuxiliaryBuffer();
154 }
155 return scanInternal(transaction, scanState);
156 }
157
158 virtual void insert(transaction::Transaction* transaction, TableInsertState& insertState) = 0;
159 virtual void update(transaction::Transaction* transaction, TableUpdateState& updateState) = 0;
160 virtual bool delete_(transaction::Transaction* transaction, TableDeleteState& deleteState) = 0;
161
162 virtual void addColumn(transaction::Transaction* transaction,
163 TableAddColumnState& addColumnState) = 0;
165
166 virtual void commit(transaction::Transaction* transaction, LocalTable* localTable) = 0;
167 virtual void checkpoint(common::Serializer& ser, catalog::TableCatalogEntry* tableEntry) = 0;
168
170
171 void setHasChanges() { hasChanges = true; }
172
173 template<class TARGET>
174 TARGET& cast() {
176 }
177 template<class TARGET>
178 const TARGET& cast() const {
180 }
181 template<class TARGET>
182 TARGET* ptrCast() {
184 }
185
186protected:
187 virtual bool scanInternal(transaction::Transaction* transaction, TableScanState& scanState) = 0;
188
189 virtual void serialize(common::Serializer& serializer) const;
190
191 std::unique_ptr<common::DataChunk> constructDataChunk(
192 const std::vector<common::LogicalType>& types);
193
194protected:
197 std::string tableName;
199 BMFileHandle* dataFH;
200 MemoryManager* memoryManager;
201 BufferManager* bufferManager;
202 ShadowFile* shadowFile;
204};
205
206} // namespace storage
207} // namespace kuzu
Definition catalog.h:48
Definition property.h:15
Definition table_catalog_entry.h:24
Definition deserializer.h:15
static LogicalType INT64()
Definition types.h:245
Definition mask.h:86
Definition serializer.h:15
Definition value_vector.h:20
Contain client side configuration. We make profiler associated per query, so profiler is not maintain...
Definition client_context.h:51
Definition local_table.h:25
Definition node_group.h:85
Definition table.h:134
virtual void insert(transaction::Transaction *transaction, TableInsertState &insertState)=0
common::TableType getTableType() const
Definition table.h:144
const TARGET & cast() const
Definition table.h:178
virtual void update(transaction::Transaction *transaction, TableUpdateState &updateState)=0
virtual void initializeScanState(transaction::Transaction *transaction, TableScanState &readState)=0
common::table_id_t tableID
Definition table.h:196
virtual void addColumn(transaction::Transaction *transaction, TableAddColumnState &addColumnState)=0
common::table_id_t getTableID() const
Definition table.h:145
void dropColumn()
Definition table.h:164
BufferManager * bufferManager
Definition table.h:201
ShadowFile * shadowFile
Definition table.h:202
TARGET * ptrCast()
Definition table.h:182
std::string getTableName() const
Definition table.h:146
BMFileHandle * dataFH
Definition table.h:199
void setHasChanges()
Definition table.h:171
bool hasChanges
Definition table.h:203
common::TableType tableType
Definition table.h:195
bool enableCompression
Definition table.h:198
MemoryManager * memoryManager
Definition table.h:200
virtual void checkpoint(common::Serializer &ser, catalog::TableCatalogEntry *tableEntry)=0
virtual common::row_idx_t getNumRows()=0
virtual ~Table()=default
virtual bool scanInternal(transaction::Transaction *transaction, TableScanState &scanState)=0
bool scan(transaction::Transaction *transaction, TableScanState &scanState)
Definition table.h:151
std::unique_ptr< common::DataChunk > constructDataChunk(const std::vector< common::LogicalType > &types)
TARGET & cast()
Definition table.h:174
Table(const catalog::TableCatalogEntry *tableEntry, StorageManager *storageManager, MemoryManager *memoryManager)
BMFileHandle * getDataFH() const
Definition table.h:147
virtual bool delete_(transaction::Transaction *transaction, TableDeleteState &deleteState)=0
std::string tableName
Definition table.h:197
virtual void serialize(common::Serializer &serializer) const
virtual void commit(transaction::Transaction *transaction, LocalTable *localTable)=0
static std::unique_ptr< Table > loadTable(common::Deserializer &deSer, const catalog::Catalog &catalog, StorageManager *storageManager, MemoryManager *memoryManager, common::VirtualFileSystem *vfs, main::ClientContext *context)
Definition transaction.h:28
uint64_t node_group_idx_t
Definition types.h:49
property_id_t column_id_t
Definition types.h:36
constexpr node_group_idx_t INVALID_NODE_GROUP_IDX
Definition types.h:50
ZoneMapCheckResult
Definition zone_map_check_result.h:8
uint64_t table_id_t
Definition internal_id_t.h:14
TO ku_dynamic_cast(FROM old)
Definition cast.h:11
TableType
Definition table_type.h:10
uint64_t row_idx_t
Definition types.h:46
TableScanSource
Definition table.h:16
Definition alter_type.h:5
evaluator::ExpressionEvaluator & defaultEvaluator
Definition table.h:124
const catalog::Property & property
Definition table.h:123
TableAddColumnState(const catalog::Property &property, evaluator::ExpressionEvaluator &defaultEvaluator)
Definition table.h:126
Definition table.h:109
const T & constCast() const
Definition table.h:113
T & cast()
Definition table.h:117
virtual ~TableDeleteState()=default
Definition table.h:74
T & cast()
Definition table.h:86
const T & constCast() const
Definition table.h:82
const std::vector< common::ValueVector * > & propertyVectors
Definition table.h:75
TableInsertState(const std::vector< common::ValueVector * > &propertyVectors)
Definition table.h:77
virtual ~TableInsertState()=default
Definition table.h:18
TARGET & cast()
Definition table.h:65
TableScanSource source
Definition table.h:29
std::vector< ColumnPredicateSet > columnPredicateSets
Definition table.h:34
std::vector< common::ValueVector * > outputVectors
Definition table.h:22
NodeGroup * nodeGroup
Definition table.h:31
const TARGETT & cast() const
Definition table.h:69
std::vector< Column * > columns
Definition table.h:27
TableScanState(std::vector< common::column_id_t > columnIDs, std::vector< Column * > columns, std::vector< ColumnPredicateSet > columnPredicateSets)
Definition table.h:41
TableScanState(std::vector< common::column_id_t > columnIDs)
Definition table.h:37
common::node_group_idx_t nodeGroupIdx
Definition table.h:30
virtual ~TableScanState()=default
TableScanState(std::vector< common::column_id_t > columnIDs, std::vector< Column * > columns)
Definition table.h:47
common::ZoneMapCheckResult zoneMapResult
Definition table.h:35
std::vector< common::column_id_t > columnIDs
Definition table.h:23
common::NodeSemiMask * semiMask
Definition table.h:24
std::unique_ptr< NodeGroupScanState > nodeGroupScanState
Definition table.h:32
virtual void resetState()
Definition table.h:56
common::ValueVector * IDVector
Definition table.h:21
DELETE_COPY_DEFAULT_MOVE(TableScanState)
std::unique_ptr< common::ValueVector > rowIdxVector
Definition table.h:19
Definition table.h:91
TableUpdateState(common::column_id_t columnID, common::ValueVector &propertyVector)
Definition table.h:95
const T & constCast() const
Definition table.h:100
common::ValueVector & propertyVector
Definition table.h:93
common::column_id_t columnID
Definition table.h:92
virtual ~TableUpdateState()=default
T & cast()
Definition table.h:104