Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ColumnDataCollectionSegment Class Reference
Collaboration diagram for duckdb::ColumnDataCollectionSegment:

Public Member Functions

 ColumnDataCollectionSegment (shared_ptr< ColumnDataAllocator > allocator, vector< LogicalType > types_p)
void AllocateNewChunk ()
VectorDataIndex AllocateVector (const LogicalType &type, ChunkMetaData &chunk_data, ChunkManagementState *chunk_state=nullptr, VectorDataIndex prev_index=VectorDataIndex())
 Allocate space for a vector of a specific type in the segment.
VectorDataIndex AllocateVector (const LogicalType &type, ChunkMetaData &chunk_data, ColumnDataAppendState &append_state, VectorDataIndex prev_index=VectorDataIndex())
 Allocate space for a vector during append.
VectorDataIndex AllocateStringHeap (idx_t size, ChunkMetaData &chunk_meta, ColumnDataAppendState &append_state, VectorDataIndex prev_index=VectorDataIndex())
 Allocate space for string data during append (BUFFER_MANAGER_ALLOCATOR only).
void InitializeChunkState (idx_t chunk_index, ChunkManagementState &state)
void ReadChunk (idx_t chunk_index, ChunkManagementState &state, DataChunk &chunk, const vector< column_t > &column_ids)
idx_t ReadVector (ChunkManagementState &state, VectorDataIndex vector_index, Vector &result)
VectorDataIndex GetChildIndex (VectorChildIndex index, idx_t child_entry=0)
VectorChildIndex AddChildIndex (VectorDataIndex index)
VectorChildIndex ReserveChildren (idx_t child_count)
void SetChildIndex (VectorChildIndex base_idx, idx_t child_number, VectorDataIndex index)
VectorMetaData & GetVectorData (VectorDataIndex index)
idx_t ChunkCount () const
idx_t SizeInBytes () const
 Get the total used size (not cached).
idx_t AllocationSize () const
 Get the currently allocated size in bytes (cached).
void FetchChunk (idx_t chunk_idx, DataChunk &result)
void FetchChunk (idx_t chunk_idx, DataChunk &result, const vector< column_t > &column_ids)
void Verify ()

Static Public Member Functions

static idx_t GetDataSize (idx_t type_size)
static validity_t * GetValidityPointerForWriting (data_ptr_t base_ptr, idx_t type_size)
static validity_t * GetValidityPointer (data_ptr_t base_ptr, idx_t type_size, idx_t count)

Public Attributes

shared_ptr< ColumnDataAllocator > allocator
vector< LogicalType > types
 The types of the chunks.
idx_t count
 The number of entries in the internal column data.
vector< ChunkMetaData > chunk_data
 Set of chunk meta data.
vector< VectorMetaData > vector_data
 Set of vector meta data.
vector< VectorDataIndex > child_indices
 The set of child indices.
shared_ptr< StringHeap > heap
 The string heap for the column data collection (only used for IN_MEMORY_ALLOCATOR).

Private Member Functions

idx_t ReadVectorInternal (ChunkManagementState &state, VectorDataIndex vector_index, Vector &result)
VectorDataIndex AllocateVectorInternal (const LogicalType &type, ChunkMetaData &chunk_meta, ChunkManagementState *chunk_state)

Constructor & Destructor Documentation

◆ ColumnDataCollectionSegment()

duckdb::ColumnDataCollectionSegment::ColumnDataCollectionSegment ( shared_ptr< ColumnDataAllocator > allocator,
vector< LogicalType > types_p )
115873 : allocator(std::move(allocator_p)), types(std::move(types_p)), count(0),
115874 heap(make_shared_ptr<StringHeap>(allocator->GetAllocator())) {
115875}
idx_t count
The number of entries in the internal column data.
Definition duckdb.cpp:113810
shared_ptr< StringHeap > heap
The string heap for the column data collection (only used for IN_MEMORY_ALLOCATOR).
Definition duckdb.cpp:113818
vector< LogicalType > types
The types of the chunks.
Definition duckdb.cpp:113808

Member Function Documentation

◆ AllocateNewChunk()

void duckdb::ColumnDataCollectionSegment::AllocateNewChunk ( )
115978 {
115979 ChunkMetaData meta_data;
115980 meta_data.count = 0;
115981 meta_data.vector_data.reserve(types.size());
115982 for (idx_t i = 0; i < types.size(); i++) {
115983 auto vector_idx = AllocateVector(types[i], meta_data);
115984 meta_data.vector_data.push_back(vector_idx);
115985 }
115986 chunk_data.push_back(std::move(meta_data));
115987}
VectorDataIndex AllocateVector(const LogicalType &type, ChunkMetaData &chunk_data, ChunkManagementState *chunk_state=nullptr, VectorDataIndex prev_index=VectorDataIndex())
Allocate space for a vector of a specific type in the segment.
Definition duckdb.cpp:115927
vector< ChunkMetaData > chunk_data
Set of chunk meta data.
Definition duckdb.cpp:113812
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ AllocateVector() [1/2]

VectorDataIndex duckdb::ColumnDataCollectionSegment::AllocateVector ( const LogicalType & type,
ChunkMetaData & chunk_data,
ChunkManagementState * chunk_state = nullptr,
VectorDataIndex prev_index = VectorDataIndex() )

Allocate space for a vector of a specific type in the segment.

115929 {
115930 auto index = AllocateVectorInternal(type, chunk_meta, chunk_state);
115931 if (prev_index.IsValid()) {
115932 GetVectorData(prev_index).next_data = index;
115933 }
115934 if (type.InternalType() == PhysicalType::STRUCT) {
115935 // initialize the struct children
115936 auto &child_types = StructType::GetChildTypes(type);
115937 auto base_child_index = ReserveChildren(child_types.size());
115938 for (idx_t child_idx = 0; child_idx < child_types.size(); child_idx++) {
115939 VectorDataIndex prev_child_index;
115940 if (prev_index.IsValid()) {
115941 prev_child_index = GetChildIndex(GetVectorData(prev_index).child_index, child_idx);
115942 }
115943 auto child_index = AllocateVector(child_types[child_idx].second, chunk_meta, chunk_state, prev_child_index);
115944 SetChildIndex(base_child_index, child_idx, child_index);
115945 }
115946 GetVectorData(index).child_index = base_child_index;
115947 }
115948 return index;
115949}
index
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllocateVector() [2/2]

VectorDataIndex duckdb::ColumnDataCollectionSegment::AllocateVector ( const LogicalType & type,
ChunkMetaData & chunk_data,
ColumnDataAppendState & append_state,
VectorDataIndex prev_index = VectorDataIndex() )

Allocate space for a vector during append.

115953 {
115954 return AllocateVector(type, chunk_meta, &append_state.current_chunk_state, prev_index);
115955}
Here is the call graph for this function:

◆ AllocateStringHeap()

VectorDataIndex duckdb::ColumnDataCollectionSegment::AllocateStringHeap ( idx_t size,
ChunkMetaData & chunk_meta,
ColumnDataAppendState & append_state,
VectorDataIndex prev_index = VectorDataIndex() )

Allocate space for string data during append (BUFFER_MANAGER_ALLOCATOR only).

115959 {
115960 D_ASSERT(allocator->GetType() == ColumnDataAllocatorType::BUFFER_MANAGER_ALLOCATOR);
115961 D_ASSERT(size != 0);
115962
115963 VectorMetaData meta_data;
115964 meta_data.count = 0;
115965 allocator->AllocateData(AlignValue(size), meta_data.block_id, meta_data.offset, &append_state.current_chunk_state);
115966 chunk_meta.block_ids.insert(meta_data.block_id);
115967
115968 VectorDataIndex index(vector_data.size());
115969 vector_data.push_back(meta_data);
115970
115971 if (prev_index.IsValid()) {
115972 GetVectorData(prev_index).next_data = index;
115973 }
115974
115975 return index;
115976}
vector< VectorMetaData > vector_data
Set of vector meta data.
Definition duckdb.cpp:113814
@ BUFFER_MANAGER_ALLOCATOR
Use a buffer manager to allocate large chunks of memory that vectors then use.
Definition duckdb.hpp:18799
static T AlignValue(T n)
Align value (ceiling) (not for pointer types).
Definition duckdb.hpp:2126
Here is the call graph for this function:

◆ InitializeChunkState()

void duckdb::ColumnDataCollectionSegment::InitializeChunkState ( idx_t chunk_index,
ChunkManagementState & state )
115989 {
115990 auto &chunk = chunk_data[chunk_index];
115991 allocator->InitializeChunkState(state, chunk);
115992}

◆ ReadChunk()

void duckdb::ColumnDataCollectionSegment::ReadChunk ( idx_t chunk_index,
ChunkManagementState & state,
DataChunk & chunk,
const vector< column_t > & column_ids )
116120 {
116121 D_ASSERT(chunk.ColumnCount() == column_ids.size());
116122 D_ASSERT(state.properties != ColumnDataScanProperties::INVALID);
116123 chunk.Reset();
116124 InitializeChunkState(chunk_index, state);
116125 auto &chunk_meta = chunk_data[chunk_index];
116126 for (idx_t i = 0; i < column_ids.size(); i++) {
116127 auto vector_idx = column_ids[i];
116128 D_ASSERT(vector_idx < chunk_meta.vector_data.size());
116129 ReadVector(state, chunk_meta.vector_data[vector_idx], chunk.data[i]);
116130 }
116131 chunk.SetCardinality(chunk_meta.count);
116132}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445

◆ ReadVector()

idx_t duckdb::ColumnDataCollectionSegment::ReadVector ( ChunkManagementState & state,
VectorDataIndex vector_index,
Vector & result )
116070 {
116071 auto &vector_type = result.GetType();
116072 auto internal_type = vector_type.InternalType();
116073 auto &vdata = GetVectorData(vector_index);
116074 if (vdata.count == 0) {
116075 return 0;
116076 }
116077 auto vcount = ReadVectorInternal(state, vector_index, result);
116078 if (internal_type == PhysicalType::LIST) {
116079 // list: copy child
116080 auto &child_vector = ListVector::GetEntry(result);
116081 auto child_count = ReadVector(state, GetChildIndex(vdata.child_index), child_vector);
116082 ListVector::SetListSize(result, child_count);
116083 } else if (internal_type == PhysicalType::ARRAY) {
116084 auto &child_vector = ArrayVector::GetEntry(result);
116085 auto child_count = ReadVector(state, GetChildIndex(vdata.child_index), child_vector);
116086 (void)child_count;
116087 } else if (internal_type == PhysicalType::STRUCT) {
116088 auto &child_vectors = StructVector::GetEntries(result);
116089 for (idx_t child_idx = 0; child_idx < child_vectors.size(); child_idx++) {
116090 auto child_count =
116091 ReadVector(state, GetChildIndex(vdata.child_index, child_idx), *child_vectors[child_idx]);
116092 if (child_count != vcount) {
116093 throw InternalException("Column Data Collection: mismatch in struct child sizes");
116094 }
116095 }
116096 } else if (internal_type == PhysicalType::VARCHAR) {
116097 if (allocator->GetType() == ColumnDataAllocatorType::BUFFER_MANAGER_ALLOCATOR) {
116098 auto next_index = vector_index;
116099 const auto copied =
116100 vdata.next_data.IsValid() || state.properties == ColumnDataScanProperties::DISALLOW_ZERO_COPY;
116101 idx_t offset = 0;
116102 while (next_index.IsValid()) {
116103 auto &current_vdata = GetVectorData(next_index);
116104 for (auto &swizzle_segment : current_vdata.swizzle_data) {
116105 auto &string_heap_segment = GetVectorData(swizzle_segment.child_index);
116106 allocator->UnswizzlePointers(state, result, swizzle_segment, string_heap_segment, offset, copied);
116107 }
116108 offset += current_vdata.count;
116109 next_index = current_vdata.next_data;
116110 }
116111 }
116112 if (state.properties == ColumnDataScanProperties::DISALLOW_ZERO_COPY) {
116113 VectorOperations::Copy(result, result, vcount, 0, 0);
116114 }
116115 }
116116 return vcount;
116117}
@ DISALLOW_ZERO_COPY
Definition duckdb.hpp:18814
@ LIST
A list of some logical data type.
Definition duckdb.hpp:2813
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of an array.
Definition duckdb.cpp:138574
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of a list.
Definition duckdb.cpp:138203
static DUCKDB_API void SetListSize(Vector &vec, idx_t size)
Sets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138248

◆ GetChildIndex()

VectorDataIndex duckdb::ColumnDataCollectionSegment::GetChildIndex ( VectorChildIndex index,
idx_t child_entry = 0 )
115994 {
115995 D_ASSERT(index.IsValid());
115996 D_ASSERT(index.index + child_entry < child_indices.size());
115997 return VectorDataIndex(child_indices[index.index + child_entry]);
115998}
vector< VectorDataIndex > child_indices
The set of child indices.
Definition duckdb.cpp:113816

◆ AddChildIndex()

VectorChildIndex duckdb::ColumnDataCollectionSegment::AddChildIndex ( VectorDataIndex index)
116000 {
116001 auto result = child_indices.size();
116002 child_indices.push_back(index);
116003 return VectorChildIndex(result);
116004}

◆ ReserveChildren()

VectorChildIndex duckdb::ColumnDataCollectionSegment::ReserveChildren ( idx_t child_count)
116006 {
116007 auto result = child_indices.size();
116008 for (idx_t i = 0; i < child_count; i++) {
116009 child_indices.emplace_back();
116010 }
116011 return VectorChildIndex(result);
116012}

◆ SetChildIndex()

void duckdb::ColumnDataCollectionSegment::SetChildIndex ( VectorChildIndex base_idx,
idx_t child_number,
VectorDataIndex index )
116014 {
116015 D_ASSERT(base_idx.IsValid());
116016 D_ASSERT(index.IsValid());
116017 D_ASSERT(base_idx.index + child_number < child_indices.size());
116018 child_indices[base_idx.index + child_number] = index;
116019}

◆ GetVectorData()

VectorMetaData & duckdb::ColumnDataCollectionSegment::GetVectorData ( VectorDataIndex index)
inline
113844 {
113845 D_ASSERT(index.index < vector_data.size());
113846 return vector_data[index.index];
113847 }

◆ ChunkCount()

idx_t duckdb::ColumnDataCollectionSegment::ChunkCount ( ) const
116134 {
116135 return chunk_data.size();
116136}

◆ SizeInBytes()

idx_t duckdb::ColumnDataCollectionSegment::SizeInBytes ( ) const

Get the total used size (not cached).

116138 {
116139 D_ASSERT(!allocator->IsShared());
116140 return allocator->SizeInBytes() + heap->SizeInBytes();
116141}

◆ AllocationSize()

idx_t duckdb::ColumnDataCollectionSegment::AllocationSize ( ) const

Get the currently allocated size in bytes (cached).

116143 {
116144 D_ASSERT(!allocator->IsShared());
116145 return allocator->AllocationSize() + heap->AllocationSize();
116146}

◆ FetchChunk() [1/2]

void duckdb::ColumnDataCollectionSegment::FetchChunk ( idx_t chunk_idx,
DataChunk & result )
116148 {
116149 vector<column_t> column_ids;
116150 column_ids.reserve(types.size());
116151 for (idx_t i = 0; i < types.size(); i++) {
116152 column_ids.push_back(i);
116153 }
116154 FetchChunk(chunk_idx, result, column_ids);
116155}

◆ FetchChunk() [2/2]

void duckdb::ColumnDataCollectionSegment::FetchChunk ( idx_t chunk_idx,
DataChunk & result,
const vector< column_t > & column_ids )
116157 {
116158 D_ASSERT(chunk_idx < chunk_data.size());
116159 ChunkManagementState state;
116161 ReadChunk(chunk_idx, state, result, column_ids);
116162}

◆ Verify()

void duckdb::ColumnDataCollectionSegment::Verify ( )
116164 {
116165#ifdef DEBUG
116166 idx_t total_count = 0;
116167 for (idx_t i = 0; i < chunk_data.size(); i++) {
116168 total_count += chunk_data[i].count;
116169 }
116170 D_ASSERT(total_count == this->count);
116171#endif
116172}

◆ GetDataSize()

idx_t duckdb::ColumnDataCollectionSegment::GetDataSize ( idx_t type_size)
static
115877 {
115878 return AlignValue(type_size * STANDARD_VECTOR_SIZE);
115879}

◆ GetValidityPointerForWriting()

validity_t * duckdb::ColumnDataCollectionSegment::GetValidityPointerForWriting ( data_ptr_t base_ptr,
idx_t type_size )
static
115881 {
115882 return reinterpret_cast<validity_t *>(base_ptr + GetDataSize(type_size));
115883}

◆ GetValidityPointer()

validity_t * duckdb::ColumnDataCollectionSegment::GetValidityPointer ( data_ptr_t base_ptr,
idx_t type_size,
idx_t count )
static
115885 {
115886 auto validity_mask = reinterpret_cast<validity_t *>(base_ptr + GetDataSize(type_size));
115887
115888 // Optimized check to see if all entries are valid
115889 for (idx_t i = 0; i < (count / ValidityMask::BITS_PER_VALUE); i++) {
115890 if (!ValidityMask::AllValid(validity_mask[i])) {
115891 return validity_mask;
115892 }
115893 }
115894
115895 if ((count % ValidityMask::BITS_PER_VALUE) != 0) {
115896 // Create a mask with the lower `bits_to_check` bits set to 1
115897 validity_t mask = (1ULL << (count % ValidityMask::BITS_PER_VALUE)) - 1;
115898 if ((validity_mask[(count / ValidityMask::BITS_PER_VALUE)] & mask) != mask) {
115899 return validity_mask;
115900 }
115901 }
115902 // All entries are valid, no need to initialize the validity mask
115903 return nullptr;
115904}
GMat mask(const GMat &src, const GMat &mask)

◆ ReadVectorInternal()

idx_t duckdb::ColumnDataCollectionSegment::ReadVectorInternal ( ChunkManagementState & state,
VectorDataIndex vector_index,
Vector & result )
private
116022 {
116023 auto &vector_type = result.GetType();
116024 auto internal_type = vector_type.InternalType();
116025 auto type_size = GetTypeIdSize(internal_type);
116026 auto &vdata = GetVectorData(vector_index);
116027
116028 auto base_ptr = allocator->GetDataPointer(state, vdata.block_id, vdata.offset);
116029 auto validity_data = GetValidityPointer(base_ptr, type_size, vdata.count);
116030 if (!vdata.next_data.IsValid() && state.properties != ColumnDataScanProperties::DISALLOW_ZERO_COPY) {
116031 // no next data, we can do a zero-copy read of this vector
116032 FlatVector::SetData(result, base_ptr);
116033 FlatVector::Validity(result).Initialize(validity_data, STANDARD_VECTOR_SIZE);
116034 return vdata.count;
116035 }
116036
116037 // the data for this vector is spread over multiple vector data entries
116038 // we need to copy over the data for each of the vectors
116039 // first figure out how many rows we need to copy by looping over all of the child vector indexes
116040 idx_t vector_count = 0;
116041 auto next_index = vector_index;
116042 while (next_index.IsValid()) {
116043 auto &current_vdata = GetVectorData(next_index);
116044 vector_count += current_vdata.count;
116045 next_index = current_vdata.next_data;
116046 }
116047 // resize the result vector
116048 result.Resize(0, vector_count);
116049 next_index = vector_index;
116050 // now perform the copy of each of the vectors
116051 auto target_data = FlatVector::GetData(result);
116052 auto &target_validity = FlatVector::Validity(result);
116053 idx_t current_offset = 0;
116054 while (next_index.IsValid()) {
116055 auto &current_vdata = GetVectorData(next_index);
116056 base_ptr = allocator->GetDataPointer(state, current_vdata.block_id, current_vdata.offset);
116057 validity_data = GetValidityPointer(base_ptr, type_size, current_vdata.count);
116058 if (type_size > 0) {
116059 memcpy(target_data + current_offset * type_size, base_ptr, current_vdata.count * type_size);
116060 }
116061 ValidityMask current_validity(validity_data, STANDARD_VECTOR_SIZE);
116062 target_validity.SliceInPlace(current_validity, current_offset, 0, current_vdata.count);
116063 current_offset += current_vdata.count;
116064 next_index = current_vdata.next_data;
116065 }
116066 return vector_count;
116067}

◆ AllocateVectorInternal()

VectorDataIndex duckdb::ColumnDataCollectionSegment::AllocateVectorInternal ( const LogicalType & type,
ChunkMetaData & chunk_meta,
ChunkManagementState * chunk_state )
private
115907 {
115908 VectorMetaData meta_data;
115909 meta_data.count = 0;
115910
115911 auto internal_type = type.InternalType();
115912 auto struct_or_array = internal_type == PhysicalType::STRUCT || internal_type == PhysicalType::ARRAY;
115913 auto type_size = struct_or_array ? 0 : GetTypeIdSize(internal_type);
115914
115915 allocator->AllocateData(GetDataSize(type_size) + ValidityMask::STANDARD_MASK_SIZE, meta_data.block_id,
115916 meta_data.offset, chunk_state);
115917 if (allocator->GetType() == ColumnDataAllocatorType::BUFFER_MANAGER_ALLOCATOR ||
115918 allocator->GetType() == ColumnDataAllocatorType::HYBRID) {
115919 chunk_meta.block_ids.insert(meta_data.block_id);
115920 }
115921
115922 auto index = vector_data.size();
115923 vector_data.push_back(meta_data);
115924 return VectorDataIndex(index);
115925}
@ HYBRID
Use a buffer manager to allocate vectors, but use a StringHeap for strings.
Definition duckdb.hpp:18804

The documentation for this class was generated from the following file: