Kùzu C++ API
Loading...
Searching...
No Matches
column_chunk.h
Go to the documentation of this file.
1#pragma once
2
3#include "column_chunk_data.h"
4#include "update_info.h"
5
6namespace kuzu {
7namespace storage {
8
18
21 std::vector<ChunkCheckpointState> chunkCheckpointStates;
23
25 std::vector<ChunkCheckpointState> chunkCheckpointStates)
28 for (const auto& chunkCheckpointState : this->chunkCheckpointStates) {
29 const auto endRowIdx = chunkCheckpointState.startRow + chunkCheckpointState.numRows;
30 if (endRowIdx > maxRowIdxToWrite) {
31 maxRowIdxToWrite = endRowIdx;
32 }
33 }
34 }
35};
36
38public:
39 ColumnChunk(const common::LogicalType& dataType, uint64_t capacity, bool enableCompression,
40 ResidencyState residencyState);
41 ColumnChunk(const common::LogicalType& dataType, bool enableCompression,
42 ColumnChunkMetadata metadata);
43 ColumnChunk(bool enableCompression, std::unique_ptr<ColumnChunkData> data);
44
45 void initializeScanState(ChunkState& state) const;
46 void scan(const transaction::Transaction* transaction, const ChunkState& state,
47 common::ValueVector& nodeID, common::ValueVector& output, common::offset_t offsetInChunk,
48 common::length_t length) const;
49 template<ResidencyState SCAN_RESIDENCY_STATE>
50 void scanCommitted(transaction::Transaction* transaction, ChunkState& chunkState,
51 ColumnChunk& output, common::row_idx_t startRow = 0,
53 void lookup(transaction::Transaction* transaction, const ChunkState& state,
54 common::offset_t rowInChunk, common::ValueVector& output,
55 common::sel_t posInOutputVector) const;
56 void update(const transaction::Transaction* transaction, common::offset_t offsetInChunk,
57 const common::ValueVector& values);
58
59 uint64_t getEstimatedMemoryUsage() const {
60 return getResidencyState() == ResidencyState::ON_DISK ? 0 : data->getEstimatedMemoryUsage();
61 }
62 void serialize(common::Serializer& serializer) const;
63 static std::unique_ptr<ColumnChunk> deserialize(common::Deserializer& deSer);
64
65 uint64_t getNumValues() const { return data->getNumValues(); }
66 void setNumValues(const uint64_t numValues) const { data->setNumValues(numValues); }
67
69
70 std::pair<std::unique_ptr<ColumnChunk>, std::unique_ptr<ColumnChunk>> scanUpdates(
71 const transaction::Transaction* transaction) const;
72
73 void setData(std::unique_ptr<ColumnChunkData> data) { this->data = std::move(data); }
74 // Functions to access the in memory data.
75 ColumnChunkData& getData() const { return *data; }
76 const ColumnChunkData& getConstData() const { return *data; }
77 std::unique_ptr<ColumnChunkData> moveData() { return std::move(data); }
78
79 common::LogicalType& getDataType() { return data->getDataType(); }
80 const common::LogicalType& getDataType() const { return data->getDataType(); }
81 bool isCompressionEnabled() const { return enableCompression; }
82
83 ResidencyState getResidencyState() const { return data->getResidencyState(); }
84 bool hasUpdates() const { return updateInfo != nullptr; }
85 bool hasUpdates(const transaction::Transaction* transaction, common::row_idx_t startRow,
86 common::length_t numRows) const;
87 // These functions should only work on in-memory and temporary column chunks.
88 void resetToEmpty() const { data->resetToEmpty(); }
89 void resetToAllNull() const { data->resetToAllNull(); }
90 void resize(uint64_t newSize) const { data->resize(newSize); }
92 if (updateInfo) {
93 updateInfo.reset();
94 }
95 }
96
97private:
98 void scanCommittedUpdates(const transaction::Transaction* transaction, ColumnChunkData& output,
99 common::offset_t startOffsetInOutput, common::row_idx_t startRowScanned,
100 common::row_idx_t numRows) const;
101
102private:
103 // TODO(Guodong): This field should be removed. Ideally it shouldn't be cached anywhere in
104 // storage structures, instead should be fed into functions needed from ClientContext dbConfig.
105 bool enableCompression;
106 std::unique_ptr<ColumnChunkData> data;
107 // Update versions.
108 std::unique_ptr<UpdateInfo> updateInfo;
109};
110
111} // namespace storage
112} // namespace kuzu
Definition deserializer.h:15
Definition types.h:201
Definition serializer.h:15
Definition value_vector.h:20
Definition column_chunk_data.h:85
Definition column_chunk.h:37
std::unique_ptr< ColumnChunkData > moveData()
Definition column_chunk.h:77
common::LogicalType & getDataType()
Definition column_chunk.h:79
bool hasUpdates() const
Definition column_chunk.h:84
uint64_t getNumValues() const
Definition column_chunk.h:65
std::pair< std::unique_ptr< ColumnChunk >, std::unique_ptr< ColumnChunk > > scanUpdates(const transaction::Transaction *transaction) const
void lookup(transaction::Transaction *transaction, const ChunkState &state, common::offset_t rowInChunk, common::ValueVector &output, common::sel_t posInOutputVector) const
void serialize(common::Serializer &serializer) const
ResidencyState getResidencyState() const
Definition column_chunk.h:83
const common::LogicalType & getDataType() const
Definition column_chunk.h:80
void setNumValues(const uint64_t numValues) const
Definition column_chunk.h:66
bool hasUpdates(const transaction::Transaction *transaction, common::row_idx_t startRow, common::length_t numRows) const
void resetToEmpty() const
Definition column_chunk.h:88
void update(const transaction::Transaction *transaction, common::offset_t offsetInChunk, const common::ValueVector &values)
common::row_idx_t getNumUpdatedRows(const transaction::Transaction *transaction) const
void scan(const transaction::Transaction *transaction, const ChunkState &state, common::ValueVector &nodeID, common::ValueVector &output, common::offset_t offsetInChunk, common::length_t length) const
static std::unique_ptr< ColumnChunk > deserialize(common::Deserializer &deSer)
void resetUpdateInfo()
Definition column_chunk.h:91
ColumnChunk(const common::LogicalType &dataType, uint64_t capacity, bool enableCompression, ResidencyState residencyState)
ColumnChunk(bool enableCompression, std::unique_ptr< ColumnChunkData > data)
uint64_t getEstimatedMemoryUsage() const
Definition column_chunk.h:59
ColumnChunk(const common::LogicalType &dataType, bool enableCompression, ColumnChunkMetadata metadata)
void resetToAllNull() const
Definition column_chunk.h:89
ColumnChunkData & getData() const
Definition column_chunk.h:75
const ColumnChunkData & getConstData() const
Definition column_chunk.h:76
void resize(uint64_t newSize) const
Definition column_chunk.h:90
void initializeScanState(ChunkState &state) const
void scanCommitted(transaction::Transaction *transaction, ChunkState &chunkState, ColumnChunk &output, common::row_idx_t startRow=0, common::row_idx_t numRows=common::INVALID_ROW_IDX) const
bool isCompressionEnabled() const
Definition column_chunk.h:81
void setData(std::unique_ptr< ColumnChunkData > data)
Definition column_chunk.h:73
Definition transaction.h:28
uint64_t length_t
Definition types.h:53
constexpr row_idx_t INVALID_ROW_IDX
Definition types.h:47
uint64_t sel_t
Definition types.h:24
uint64_t offset_t
Definition internal_id_t.h:22
uint64_t row_idx_t
Definition types.h:46
ResidencyState
Definition residency_state.h:11
Definition alter_type.h:5
Definition column_chunk.h:9
std::unique_ptr< ColumnChunkData > chunkData
Definition column_chunk.h:10
common::row_idx_t startRow
Definition column_chunk.h:11
ChunkCheckpointState(std::unique_ptr< ColumnChunkData > chunkData, common::row_idx_t startRow, common::length_t numRows)
Definition column_chunk.h:14
common::length_t numRows
Definition column_chunk.h:12
Definition column_chunk_data.h:45
Definition column_chunk.h:19
common::row_idx_t maxRowIdxToWrite
Definition column_chunk.h:22
ColumnCheckpointState(ColumnChunkData &persistentData, std::vector< ChunkCheckpointState > chunkCheckpointStates)
Definition column_chunk.h:24
ColumnChunkData & persistentData
Definition column_chunk.h:20
std::vector< ChunkCheckpointState > chunkCheckpointStates
Definition column_chunk.h:21
Definition column_chunk_data.h:29