Kùzu C++ API
Loading...
Searching...
No Matches
chunked_node_group.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4
5#include "rel_multiplicity.h"
6#include "internal_id_t.h"
7#include "residency_state.h"
8#include "column_chunk.h"
9#include "column_chunk_data.h"
10#include "version_info.h"
11
12namespace kuzu {
13namespace common {
14class SelectionVector;
15} // namespace common
16
17namespace transaction {
18class Transaction;
19} // namespace transaction
20
21namespace storage {
22
23class Column;
24struct TableScanState;
25struct TableAddColumnState;
26struct NodeGroupScanState;
27
28enum class NodeGroupDataFormat : uint8_t { REGULAR = 0, CSR = 1 };
29
31public:
32 static constexpr uint64_t CHUNK_CAPACITY = 2048;
33
34 ChunkedNodeGroup(std::vector<std::unique_ptr<ColumnChunk>> chunks,
37 const std::vector<common::column_id_t>& selectedColumns);
38 ChunkedNodeGroup(const std::vector<common::LogicalType>& columnTypes, bool enableCompression,
41 virtual ~ChunkedNodeGroup() = default;
42
43 common::idx_t getNumColumns() const { return chunks.size(); }
47 const ColumnChunk& getColumnChunk(const common::column_id_t columnID) const {
48 KU_ASSERT(columnID < chunks.size());
49 return *chunks[columnID];
50 }
52 KU_ASSERT(columnID < chunks.size());
53 return *chunks[columnID];
54 }
55 std::unique_ptr<ColumnChunk> moveColumnChunk(const common::column_id_t columnID) {
56 KU_ASSERT(columnID < chunks.size());
57 return std::move(chunks[columnID]);
58 }
59 bool isFullOrOnDisk() const {
61 }
64
66 void resetToAllNull() const;
69 void resizeChunks(uint64_t newSize);
70 void setVersionInfo(std::unique_ptr<VersionInfo> versionInfo) {
71 this->versionInfo = std::move(versionInfo);
72 }
74
75 uint64_t append(const transaction::Transaction* transaction,
76 const std::vector<common::ValueVector*>& columnVectors, common::row_idx_t startRowInVectors,
77 uint64_t numValuesToAppend);
78 // Appends up to numValuesToAppend from the other chunked node group, returning the actual
79 // number of values appended.
81 const ChunkedNodeGroup& other, common::offset_t offsetInOtherNodeGroup,
82 common::offset_t numRowsToAppend);
84 const std::vector<ColumnChunk*>& other, common::offset_t offsetInOtherNodeGroup,
85 common::offset_t numRowsToAppend);
86 void write(const ChunkedNodeGroup& data, common::column_id_t offsetColumnID);
87
88 void scan(const transaction::Transaction* transaction, const TableScanState& scanState,
89 const NodeGroupScanState& nodeGroupScanState, common::offset_t rowIdxInGroup,
90 common::length_t numRowsToScan) const;
91
92 template<ResidencyState SCAN_RESIDENCY_STATE>
94 NodeGroupScanState& nodeGroupScanState, ChunkedNodeGroup& output) const;
95
96 bool hasUpdates() const;
99 common::column_id_t columnID);
100
101 std::pair<std::unique_ptr<ColumnChunk>, std::unique_ptr<ColumnChunk>> scanUpdates(
102 transaction::Transaction* transaction, common::column_id_t columnID);
103
104 bool lookup(transaction::Transaction* transaction, const TableScanState& state,
105 NodeGroupScanState& nodeGroupScanState, common::offset_t rowIdxInChunk,
106 common::sel_t posInOutput) const;
107
108 void update(transaction::Transaction* transaction, common::row_idx_t rowIdxInChunk,
109 common::column_id_t columnID, const common::ValueVector& propertyVector);
110
111 bool delete_(const transaction::Transaction* transaction, common::row_idx_t rowIdxInChunk);
112
113 void addColumn(transaction::Transaction* transaction, const TableAddColumnState& addColumnState,
114 bool enableCompression, BMFileHandle* dataFH);
115
116 bool isDeleted(const transaction::Transaction* transaction, common::row_idx_t rowInChunk) const;
117 bool isInserted(const transaction::Transaction* transaction,
118 common::row_idx_t rowInChunk) const;
123 bool hasVersionInfo() const { return versionInfo != nullptr; }
124
125 void finalize() const;
126
127 virtual void writeToColumnChunk(common::idx_t chunkIdx, common::idx_t vectorIdx,
128 const std::vector<std::unique_ptr<ColumnChunk>>& data, ColumnChunk& offsetChunk) {
130 chunks[chunkIdx]->getData().write(&data[vectorIdx]->getData(), &offsetChunk.getData(),
132 }
133
134 virtual std::unique_ptr<ChunkedNodeGroup> flushAsNewChunkedNodeGroup(
135 transaction::Transaction* transaction, BMFileHandle& dataFH) const;
136 virtual void flush(BMFileHandle& dataFH);
137
138 uint64_t getEstimatedMemoryUsage() const;
139
140 virtual void serialize(common::Serializer& serializer) const;
141 static std::unique_ptr<ChunkedNodeGroup> deserialize(common::Deserializer& deSer);
142
143 template<class TARGET>
144 TARGET& cast() {
146 }
147 template<class TARGETT>
148 const TARGETT& cast() const {
150 }
151
152protected:
156 uint64_t capacity;
157 std::atomic<common::row_idx_t> numRows;
158 std::vector<std::unique_ptr<ColumnChunk>> chunks;
159 std::unique_ptr<VersionInfo> versionInfo;
160};
161
162} // namespace storage
163} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
Definition deserializer.h:15
Definition serializer.h:15
Definition value_vector.h:20
Definition chunked_node_group.h:30
virtual void serialize(common::Serializer &serializer) const
common::row_idx_t getNumDeletions(const transaction::Transaction *transaction, common::row_idx_t startRow, common::length_t numRows) const
virtual ~ChunkedNodeGroup()=default
void update(transaction::Transaction *transaction, common::row_idx_t rowIdxInChunk, common::column_id_t columnID, const common::ValueVector &propertyVector)
common::offset_t append(const transaction::Transaction *transaction, const ChunkedNodeGroup &other, common::offset_t offsetInOtherNodeGroup, common::offset_t numRowsToAppend)
std::vector< std::unique_ptr< ColumnChunk > > chunks
Definition chunked_node_group.h:158
common::row_idx_t getNumUpdatedRows(const transaction::Transaction *transaction, common::column_id_t columnID)
bool isFullOrOnDisk() const
Definition chunked_node_group.h:59
const TARGETT & cast() const
Definition chunked_node_group.h:148
void addColumn(transaction::Transaction *transaction, const TableAddColumnState &addColumnState, bool enableCompression, BMFileHandle *dataFH)
std::unique_ptr< ColumnChunk > moveColumnChunk(const common::column_id_t columnID)
Definition chunked_node_group.h:55
NodeGroupDataFormat format
Definition chunked_node_group.h:153
ColumnChunk & getColumnChunk(const common::column_id_t columnID)
Definition chunked_node_group.h:51
ResidencyState getResidencyState() const
Definition chunked_node_group.h:62
ChunkedNodeGroup(std::vector< std::unique_ptr< ColumnChunk > > chunks, common::row_idx_t startRowIdx, NodeGroupDataFormat format=NodeGroupDataFormat::REGULAR)
std::pair< std::unique_ptr< ColumnChunk >, std::unique_ptr< ColumnChunk > > scanUpdates(transaction::Transaction *transaction, common::column_id_t columnID)
void resizeChunks(uint64_t newSize)
void scanCommitted(transaction::Transaction *transaction, TableScanState &scanState, NodeGroupScanState &nodeGroupScanState, ChunkedNodeGroup &output) const
common::offset_t append(const transaction::Transaction *transaction, const std::vector< ColumnChunk * > &other, common::offset_t offsetInOtherNodeGroup, common::offset_t numRowsToAppend)
common::idx_t getNumColumns() const
Definition chunked_node_group.h:43
ChunkedNodeGroup(const std::vector< common::LogicalType > &columnTypes, bool enableCompression, uint64_t capacity, common::row_idx_t startRowIdx, ResidencyState residencyState, NodeGroupDataFormat format=NodeGroupDataFormat::REGULAR)
uint64_t append(const transaction::Transaction *transaction, const std::vector< common::ValueVector * > &columnVectors, common::row_idx_t startRowInVectors, uint64_t numValuesToAppend)
common::row_idx_t getNumRows() const
Definition chunked_node_group.h:45
common::row_idx_t getCapacity() const
Definition chunked_node_group.h:46
static std::unique_ptr< ChunkedNodeGroup > deserialize(common::Deserializer &deSer)
std::unique_ptr< VersionInfo > versionInfo
Definition chunked_node_group.h:159
NodeGroupDataFormat getFormat() const
Definition chunked_node_group.h:63
virtual std::unique_ptr< ChunkedNodeGroup > flushAsNewChunkedNodeGroup(transaction::Transaction *transaction, BMFileHandle &dataFH) const
void write(const ChunkedNodeGroup &data, common::column_id_t offsetColumnID)
bool hasAnyUpdates(const transaction::Transaction *transaction, common::column_id_t columnID, common::row_idx_t startRow, common::length_t numRows) const
void setVersionInfo(std::unique_ptr< VersionInfo > versionInfo)
Definition chunked_node_group.h:70
common::row_idx_t getStartRowIdx() const
Definition chunked_node_group.h:44
uint64_t getEstimatedMemoryUsage() const
void scan(const transaction::Transaction *transaction, const TableScanState &scanState, const NodeGroupScanState &nodeGroupScanState, common::offset_t rowIdxInGroup, common::length_t numRowsToScan) const
ChunkedNodeGroup(ChunkedNodeGroup &base, const std::vector< common::column_id_t > &selectedColumns)
bool isDeleted(const transaction::Transaction *transaction, common::row_idx_t rowInChunk) const
common::row_idx_t startRowIdx
Definition chunked_node_group.h:155
TARGET & cast()
Definition chunked_node_group.h:144
ResidencyState residencyState
Definition chunked_node_group.h:154
static constexpr uint64_t CHUNK_CAPACITY
Definition chunked_node_group.h:32
common::row_idx_t getNumDeletedRows(const transaction::Transaction *transaction) const
virtual void flush(BMFileHandle &dataFH)
const ColumnChunk & getColumnChunk(const common::column_id_t columnID) const
Definition chunked_node_group.h:47
virtual void writeToColumnChunk(common::idx_t chunkIdx, common::idx_t vectorIdx, const std::vector< std::unique_ptr< ColumnChunk > > &data, ColumnChunk &offsetChunk)
Definition chunked_node_group.h:127
bool delete_(const transaction::Transaction *transaction, common::row_idx_t rowIdxInChunk)
bool isInserted(const transaction::Transaction *transaction, common::row_idx_t rowInChunk) const
bool lookup(transaction::Transaction *transaction, const TableScanState &state, NodeGroupScanState &nodeGroupScanState, common::offset_t rowIdxInChunk, common::sel_t posInOutput) const
uint64_t capacity
Definition chunked_node_group.h:156
void setNumRows(common::offset_t numRows_)
std::atomic< common::row_idx_t > numRows
Definition chunked_node_group.h:157
bool hasVersionInfo() const
Definition chunked_node_group.h:123
Definition column_chunk.h:37
ColumnChunkData & getData() const
Definition column_chunk.h:75
Definition transaction.h:28
uint64_t length_t
Definition types.h:53
uint32_t idx_t
Definition types.h:39
property_id_t column_id_t
Definition types.h:36
uint64_t sel_t
Definition types.h:24
TO ku_dynamic_cast(FROM old)
Definition cast.h:11
uint64_t offset_t
Definition internal_id_t.h:22
uint64_t row_idx_t
Definition types.h:46
NodeGroupDataFormat
Definition chunked_node_group.h:28
ResidencyState
Definition residency_state.h:11
Definition alter_type.h:5
Definition node_group.h:17
Definition table.h:18