Kùzu C++ API
Loading...
Searching...
No Matches
auxiliary_buffer.h
Go to the documentation of this file.
1#pragma once
2
3#include "api.h"
5#include "types.h"
6
7namespace arrow {
8class ChunkedArray;
9} // namespace arrow
10
11namespace kuzu {
12namespace common {
13
14class ValueVector;
15
16// AuxiliaryBuffer holds data which is only used by the targeting dataType.
18public:
19 virtual ~AuxiliaryBuffer() = default;
20
21 template<class TARGET>
22 TARGET& cast() {
24 }
25
26 template<class TARGET>
27 const TARGET& constCast() const {
29 }
30};
31
33public:
34 explicit StringAuxiliaryBuffer(storage::MemoryManager* memoryManager) {
35 inMemOverflowBuffer = std::make_unique<InMemOverflowBuffer>(memoryManager);
36 }
37
38 InMemOverflowBuffer* getOverflowBuffer() const { return inMemOverflowBuffer.get(); }
39 uint8_t* allocateOverflow(uint64_t size) { return inMemOverflowBuffer->allocateSpace(size); }
40 void resetOverflowBuffer() const { inMemOverflowBuffer->resetBuffer(); }
41
42private:
43 std::unique_ptr<InMemOverflowBuffer> inMemOverflowBuffer;
44};
45
47public:
48 StructAuxiliaryBuffer(const LogicalType& type, storage::MemoryManager* memoryManager);
49
50 void referenceChildVector(idx_t idx, std::shared_ptr<ValueVector> vectorToReference) {
51 childrenVectors[idx] = std::move(vectorToReference);
52 }
53 const std::vector<std::shared_ptr<ValueVector>>& getFieldVectors() const {
54 return childrenVectors;
55 }
56 std::shared_ptr<ValueVector> getFieldVectorShared(idx_t idx) const {
57 return childrenVectors[idx];
58 }
59 ValueVector* getFieldVectorPtr(idx_t idx) const { return childrenVectors[idx].get(); }
60
61private:
62 std::vector<std::shared_ptr<ValueVector>> childrenVectors;
63};
64
66 friend class ArrowColumnVector;
67
68private:
69 std::shared_ptr<arrow::ChunkedArray> column;
70};
71
72// ListVector layout:
73// To store a list value in the valueVector, we could use two separate vectors.
74// 1. A vector(called offset vector) for the list offsets and length(called list_entry_t): This
75// vector contains the starting indices and length for each list within the data vector.
76// 2. A data vector(called dataVector) to store the actual list elements: This vector holds the
77// actual elements of the lists in a flat, continuous storage. Each list would be represented as a
78// contiguous subsequence of elements in this vector.
80 friend class ListVector;
81
82public:
83 ListAuxiliaryBuffer(const LogicalType& dataVectorType, storage::MemoryManager* memoryManager);
84
85 void setDataVector(std::shared_ptr<ValueVector> vector) { dataVector = std::move(vector); }
86 ValueVector* getDataVector() const { return dataVector.get(); }
87 std::shared_ptr<ValueVector> getSharedDataVector() const { return dataVector; }
88
90
91 uint64_t getSize() const { return size; }
92
93 void resetSize() { size = 0; }
94
95 void resize(uint64_t numValues);
96
97private:
98 void resizeDataVector(ValueVector* dataVector);
99
100 void resizeStructDataVector(ValueVector* dataVector);
101
102private:
103 uint64_t capacity;
104 uint64_t size;
105
106 std::shared_ptr<ValueVector> dataVector;
107};
108
110public:
111 static std::unique_ptr<AuxiliaryBuffer> getAuxiliaryBuffer(LogicalType& type,
112 storage::MemoryManager* memoryManager);
113};
114
115} // namespace common
116} // namespace kuzu
#define KUZU_API
Definition api.h:25
Definition auxiliary_buffer.h:65
friend class ArrowColumnVector
Definition auxiliary_buffer.h:66
Definition auxiliary_buffer.h:109
static std::unique_ptr< AuxiliaryBuffer > getAuxiliaryBuffer(LogicalType &type, storage::MemoryManager *memoryManager)
Definition auxiliary_buffer.h:17
virtual ~AuxiliaryBuffer()=default
TARGET & cast()
Definition auxiliary_buffer.h:22
const TARGET & constCast() const
Definition auxiliary_buffer.h:27
Definition in_mem_overflow_buffer.h:30
Definition auxiliary_buffer.h:79
uint64_t getSize() const
Definition auxiliary_buffer.h:91
void resize(uint64_t numValues)
ValueVector * getDataVector() const
Definition auxiliary_buffer.h:86
std::shared_ptr< ValueVector > getSharedDataVector() const
Definition auxiliary_buffer.h:87
list_entry_t addList(list_size_t listSize)
ListAuxiliaryBuffer(const LogicalType &dataVectorType, storage::MemoryManager *memoryManager)
void resetSize()
Definition auxiliary_buffer.h:93
void setDataVector(std::shared_ptr< ValueVector > vector)
Definition auxiliary_buffer.h:85
Definition value_vector.h:150
Definition types.h:246
Definition auxiliary_buffer.h:32
StringAuxiliaryBuffer(storage::MemoryManager *memoryManager)
Definition auxiliary_buffer.h:34
void resetOverflowBuffer() const
Definition auxiliary_buffer.h:40
InMemOverflowBuffer * getOverflowBuffer() const
Definition auxiliary_buffer.h:38
uint8_t * allocateOverflow(uint64_t size)
Definition auxiliary_buffer.h:39
Definition auxiliary_buffer.h:46
void referenceChildVector(idx_t idx, std::shared_ptr< ValueVector > vectorToReference)
Definition auxiliary_buffer.h:50
std::shared_ptr< ValueVector > getFieldVectorShared(idx_t idx) const
Definition auxiliary_buffer.h:56
StructAuxiliaryBuffer(const LogicalType &type, storage::MemoryManager *memoryManager)
const std::vector< std::shared_ptr< ValueVector > > & getFieldVectors() const
Definition auxiliary_buffer.h:53
ValueVector * getFieldVectorPtr(idx_t idx) const
Definition auxiliary_buffer.h:59
Definition value_vector.h:20
Definition auxiliary_buffer.h:7
uint32_t idx_t
Definition types.h:41
uint32_t list_size_t
Definition types.h:56
TO ku_dynamic_cast(FROM *old)
Definition cast.h:11
Definition array_utils.h:7
Definition types.h:108