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::ColumnDataCollection Class Reference

#include <duckdb.hpp>

Collaboration diagram for duckdb::ColumnDataCollection:

Public Member Functions

DUCKDB_API ColumnDataCollection (Allocator &allocator, vector< LogicalType > types)
 Constructs an in-memory column data collection from an allocator.
DUCKDB_API ColumnDataCollection (Allocator &allocator)
 Constructs an empty (but valid) in-memory column data collection from an allocator.
DUCKDB_API ColumnDataCollection (BufferManager &buffer_manager, vector< LogicalType > types, ColumnDataCollectionLifetime lifetime=ColumnDataCollectionLifetime::REGULAR)
 Constructs a buffer-managed column data collection.
DUCKDB_API ColumnDataCollection (ClientContext &context, vector< LogicalType > types, ColumnDataAllocatorType type=ColumnDataAllocatorType::BUFFER_MANAGER_ALLOCATOR, ColumnDataCollectionLifetime lifetime=ColumnDataCollectionLifetime::REGULAR)
 Constructs either an in-memory or a buffer-managed column data collection.
DUCKDB_API ColumnDataCollection (ColumnDataCollection &parent)
DUCKDB_API ColumnDataCollection (shared_ptr< ColumnDataAllocator > allocator, vector< LogicalType > types)
vector< LogicalType > & Types ()
 The types of columns in the ColumnDataCollection.
const vector< LogicalType > & Types () const
const idx_t & Count () const
 The amount of rows in the ColumnDataCollection.
idx_t ColumnCount () const
 The amount of columns in the ColumnDataCollection.
idx_t SizeInBytes () const
 The size (in bytes) of this ColumnDataCollection.
idx_t AllocationSize () const
 The allocation size (in bytes) of this ColumnDataCollection - this property is cached.
void SetPartitionIndex (idx_t index)
 Sets the partition index of this ColumnDataCollection.
DUCKDB_API Allocator & GetAllocator () const
 Get the allocator.
DUCKDB_API void InitializeAppend (ColumnDataAppendState &state)
 Initializes an Append state - useful for optimizing many appends made to the same column data collection.
DUCKDB_API void Append (ColumnDataAppendState &state, DataChunk &new_chunk)
 Append a DataChunk to this ColumnDataCollection using the specified append state.
DUCKDB_API void InitializeScanChunk (DataChunk &chunk) const
 Initializes a chunk with the correct types that can be used to call Scan.
DUCKDB_API void InitializeScanChunk (Allocator &allocator, DataChunk &chunk) const
DUCKDB_API void InitializeScanChunk (ColumnDataScanState &state, DataChunk &chunk) const
 Initializes a chunk with the correct types for a given scan state.
DUCKDB_API void InitializeScan (ColumnDataScanState &state, ColumnDataScanProperties properties=ColumnDataScanProperties::ALLOW_ZERO_COPY) const
 Initializes a Scan state for scanning all columns.
DUCKDB_API void InitializeScan (ColumnDataScanState &state, vector< column_t > column_ids, ColumnDataScanProperties properties=ColumnDataScanProperties::ALLOW_ZERO_COPY) const
 Initializes a Scan state for scanning a subset of the columns.
DUCKDB_API void InitializeScan (ColumnDataParallelScanState &state, ColumnDataScanProperties properties=ColumnDataScanProperties::ALLOW_ZERO_COPY) const
 Initialize a parallel scan over the column data collection over all columns.
DUCKDB_API void InitializeScan (ColumnDataParallelScanState &state, vector< column_t > column_ids, ColumnDataScanProperties properties=ColumnDataScanProperties::ALLOW_ZERO_COPY) const
 Initialize a parallel scan over the column data collection over a subset of the columns.
DUCKDB_API bool Scan (ColumnDataScanState &state, DataChunk &result) const
 Scans a DataChunk from the ColumnDataCollection.
DUCKDB_API bool Scan (ColumnDataParallelScanState &state, ColumnDataLocalScanState &lstate, DataChunk &result) const
 Scans a DataChunk from the ColumnDataCollection.
DUCKDB_API void Append (DataChunk &new_chunk)
 Append a DataChunk directly to this ColumnDataCollection - calls InitializeAppend and Append internally.
DUCKDB_API void Combine (ColumnDataCollection &other)
 Appends the other ColumnDataCollection to this, destroying the other data collection.
DUCKDB_API void Verify ()
DUCKDB_API string ToString () const
DUCKDB_API void Print () const
DUCKDB_API void Reset ()
DUCKDB_API idx_t ChunkCount () const
 Returns the number of data chunks present in the ColumnDataCollection.
DUCKDB_API void FetchChunk (idx_t chunk_idx, DataChunk &result) const
 Fetch an individual chunk from the ColumnDataCollection.
DUCKDB_API ColumnDataChunkIterationHelper Chunks () const
DUCKDB_API ColumnDataChunkIterationHelper Chunks (vector< column_t > column_ids) const
DUCKDB_API ColumnDataRowIterationHelper Rows () const
DUCKDB_API ColumnDataRowCollection GetRows () const
bool NextScanIndex (ColumnDataScanState &state, idx_t &chunk_index, idx_t &segment_index, idx_t &row_index) const
 Obtains the next scan index to scan from.
bool PrevScanIndex (ColumnDataScanState &state, idx_t &chunk_index, idx_t &segment_index, idx_t &row_index) const
 Obtains the previous scan index to scan from.
void ScanAtIndex (ColumnDataParallelScanState &state, ColumnDataLocalScanState &lstate, DataChunk &result, idx_t chunk_index, idx_t segment_index, idx_t row_index) const
 Scans at the indices (obtained from NextScanIndex).
bool Seek (idx_t row_idx, ColumnDataScanState &state, DataChunk &result) const
void Initialize (vector< LogicalType > types)
 Initialize the column data collection.
vector< shared_ptr< StringHeap > > GetHeapReferences ()
 Get references to the string heaps in this ColumnDataCollection.
ColumnDataAllocatorType GetAllocatorType () const
 Get the allocator type of this ColumnDataCollection.
BufferManager & GetBufferManager () const
 Get the buffer manager of the allocator.
const vector< unique_ptr< ColumnDataCollectionSegment > > & GetSegments () const
 Get a vector of the segments in this ColumnDataCollection.
void Serialize (Serializer &serializer) const

Static Public Member Functions

static bool ResultEquals (const ColumnDataCollection &left, const ColumnDataCollection &right, string &error_message, bool ordered=false)
static unique_ptr< ColumnDataCollection > Deserialize (Deserializer &deserializer)

Private Member Functions

void CreateSegment ()
 Creates a new segment within the ColumnDataCollection.

Static Private Member Functions

static ColumnDataCopyFunction GetCopyFunction (const LogicalType &type)

Private Attributes

buffer_ptr< ColumnDataAllocator > allocator
 The Column Data Allocator.
vector< LogicalType > types
 The types of the stored entries.
idx_t count
 The number of entries stored in the column data collection.
vector< unique_ptr< ColumnDataCollectionSegment > > segments
 The data segments of the column data collection.
vector< ColumnDataCopyFunction > copy_functions
 The set of copy functions.
bool finished_append
 When the column data collection is marked as finished - new tuples can no longer be appended to it.
optional_idx partition_index
 Partition index (optional, if partitioned).

Detailed Description

The ColumnDataCollection represents a set of (buffer-managed) data stored in columnar format It is efficient to read and scan

Constructor & Destructor Documentation

◆ ColumnDataCollection() [1/6]

duckdb::ColumnDataCollection::ColumnDataCollection ( Allocator & allocator,
vector< LogicalType > types )

Constructs an in-memory column data collection from an allocator.

114488 {
114489 Initialize(std::move(types_p));
114490 allocator = make_shared_ptr<ColumnDataAllocator>(allocator_p);
114491}
void Initialize(vector< LogicalType > types)
Initialize the column data collection.
Definition duckdb.cpp:114519
buffer_ptr< ColumnDataAllocator > allocator
The Column Data Allocator.
Definition duckdb.hpp:19128
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ColumnDataCollection() [2/6]

duckdb::ColumnDataCollection::ColumnDataCollection ( Allocator & allocator)
explicit

Constructs an empty (but valid) in-memory column data collection from an allocator.

Explicitly initialized without types.

114481 {
114482 types.clear();
114483 count = 0;
114484 this->finished_append = false;
114485 allocator = make_shared_ptr<ColumnDataAllocator>(allocator_p);
114486}
idx_t count
The number of entries stored in the column data collection.
Definition duckdb.hpp:19132
bool finished_append
When the column data collection is marked as finished - new tuples can no longer be appended to it.
Definition duckdb.hpp:19138
vector< LogicalType > types
The types of the stored entries.
Definition duckdb.hpp:19130

◆ ColumnDataCollection() [3/6]

duckdb::ColumnDataCollection::ColumnDataCollection ( BufferManager & buffer_manager,
vector< LogicalType > types,
ColumnDataCollectionLifetime lifetime = ColumnDataCollectionLifetime::REGULAR )

Constructs a buffer-managed column data collection.

114494 {
114495 Initialize(std::move(types_p));
114496 allocator = make_shared_ptr<ColumnDataAllocator>(buffer_manager, lifetime);
114497}
Here is the call graph for this function:

◆ ColumnDataCollection() [4/6]

Constructs either an in-memory or a buffer-managed column data collection.

114506 : ColumnDataCollection(make_shared_ptr<ColumnDataAllocator>(context, type, lifetime), std::move(types_p)) {
114507 D_ASSERT(!types.empty());
114508}
DUCKDB_API ColumnDataCollection(Allocator &allocator, vector< LogicalType > types)
Constructs an in-memory column data collection from an allocator.
Definition duckdb.cpp:114488
Here is the call graph for this function:

◆ ColumnDataCollection() [5/6]

duckdb::ColumnDataCollection::ColumnDataCollection ( ColumnDataCollection & parent)

Creates a column data collection that inherits the blocks to write to. This allows blocks to be shared between multiple column data collections and prevents wasting space. Note that after one CDC inherits blocks from another, the other cannot be written to anymore (i.e. we take ownership of the half-written blocks).

114511 : ColumnDataCollection(other.allocator, other.types) {
114512 other.finished_append = true;
114513 D_ASSERT(!types.empty());
114514}
Here is the call graph for this function:

◆ ColumnDataCollection() [6/6]

duckdb::ColumnDataCollection::ColumnDataCollection ( shared_ptr< ColumnDataAllocator > allocator,
vector< LogicalType > types )
114499 {
114500 Initialize(std::move(types_p));
114501 this->allocator = std::move(allocator_p);
114502}

◆ ~ColumnDataCollection()

duckdb::ColumnDataCollection::~ColumnDataCollection ( )
114516 {
114517}

Member Function Documentation

◆ Types() [1/2]

vector< LogicalType > & duckdb::ColumnDataCollection::Types ( )
inline

The types of columns in the ColumnDataCollection.

18993 {
18994 return types;
18995 }

◆ Types() [2/2]

const vector< LogicalType > & duckdb::ColumnDataCollection::Types ( ) const
inline
18996 {
18997 return types;
18998 }

◆ Count()

const idx_t & duckdb::ColumnDataCollection::Count ( ) const
inline

The amount of rows in the ColumnDataCollection.

19001 {
19002 return count;
19003 }
Here is the caller graph for this function:

◆ ColumnCount()

idx_t duckdb::ColumnDataCollection::ColumnCount ( ) const
inline

The amount of columns in the ColumnDataCollection.

19006 {
19007 return types.size();
19008 }
Here is the caller graph for this function:

◆ SizeInBytes()

idx_t duckdb::ColumnDataCollection::SizeInBytes ( ) const

The size (in bytes) of this ColumnDataCollection.

114538 {
114539 idx_t total_size = 0;
114540 for (const auto &segment : segments) {
114541 total_size += segment->SizeInBytes();
114542 }
114543 return total_size;
114544}
vector< unique_ptr< ColumnDataCollectionSegment > > segments
The data segments of the column data collection.
Definition duckdb.hpp:19134
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ AllocationSize()

idx_t duckdb::ColumnDataCollection::AllocationSize ( ) const

The allocation size (in bytes) of this ColumnDataCollection - this property is cached.

114546 {
114547 idx_t total_size = 0;
114548 for (const auto &segment : segments) {
114549 total_size += segment->AllocationSize();
114550 }
114551 return total_size;
114552}

◆ SetPartitionIndex()

void duckdb::ColumnDataCollection::SetPartitionIndex ( idx_t index)

Sets the partition index of this ColumnDataCollection.

114554 {
114555 D_ASSERT(!partition_index.IsValid());
114556 D_ASSERT(Count() == 0);
114558 allocator->SetPartitionIndex(index);
114559}
optional_idx partition_index
Partition index (optional, if partitioned).
Definition duckdb.hpp:19140
const idx_t & Count() const
The amount of rows in the ColumnDataCollection.
Definition duckdb.hpp:19001
index
Here is the call graph for this function:

◆ GetAllocator()

Allocator & duckdb::ColumnDataCollection::GetAllocator ( ) const

Get the allocator.

114534 {
114535 return allocator->GetAllocator();
114536}

◆ InitializeAppend()

void duckdb::ColumnDataCollection::InitializeAppend ( ColumnDataAppendState & state)

Initializes an Append state - useful for optimizing many appends made to the same column data collection.

114753 {
114754 D_ASSERT(!finished_append);
114755 state.current_chunk_state.handles.clear();
114756 state.vector_data.resize(types.size());
114757 if (segments.empty()) {
114758 CreateSegment();
114759 }
114760 auto &segment = *segments.back();
114761 if (segment.chunk_data.empty()) {
114762 segment.AllocateNewChunk();
114763 }
114764 segment.InitializeChunkState(segment.chunk_data.size() - 1, state.current_chunk_state);
114765}
void CreateSegment()
Creates a new segment within the ColumnDataCollection.
Definition duckdb.cpp:114530
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Append() [1/2]

void duckdb::ColumnDataCollection::Append ( ColumnDataAppendState & state,
DataChunk & new_chunk )

Append a DataChunk to this ColumnDataCollection using the specified append state.

115403 {
115404 D_ASSERT(!finished_append);
115405 {
115406 auto input_types = input.GetTypes();
115407 D_ASSERT(types == input_types);
115408 }
115409
115410 auto &segment = *segments.back();
115411 for (idx_t vector_idx = 0; vector_idx < types.size(); vector_idx++) {
115412 if (IsComplexType(input.data[vector_idx].GetType())) {
115413 input.data[vector_idx].Flatten(input.size());
115414 }
115415 input.data[vector_idx].ToUnifiedFormat(input.size(), state.vector_data[vector_idx]);
115416 }
115417
115418 idx_t remaining = input.size();
115419 while (remaining > 0) {
115420 auto &chunk_data = segment.chunk_data.back();
115421 idx_t append_amount = MinValue<idx_t>(remaining, STANDARD_VECTOR_SIZE - chunk_data.count);
115422 if (append_amount > 0) {
115423 idx_t offset = input.size() - remaining;
115424 for (idx_t vector_idx = 0; vector_idx < types.size(); vector_idx++) {
115425 ColumnDataMetaData meta_data(copy_functions[vector_idx], segment, state, chunk_data,
115426 chunk_data.vector_data[vector_idx]);
115427 copy_functions[vector_idx].function(meta_data, state.vector_data[vector_idx], input.data[vector_idx],
115428 offset, append_amount);
115429 }
115430 chunk_data.count += append_amount;
115431 }
115432 remaining -= append_amount;
115433 if (remaining > 0) {
115434 // more to do
115435 // allocate a new chunk
115436 segment.AllocateNewChunk();
115437 segment.InitializeChunkState(segment.chunk_data.size() - 1, state.current_chunk_state);
115438 }
115439 }
115440 segment.count += input.size();
115441 count += input.size();
115442}
vector< ColumnDataCopyFunction > copy_functions
The set of copy functions.
Definition duckdb.hpp:19136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeScanChunk() [1/3]

void duckdb::ColumnDataCollection::InitializeScanChunk ( DataChunk & chunk) const

Initializes a chunk with the correct types that can be used to call Scan.

115502 {
115503 InitializeScanChunk(allocator->GetAllocator(), chunk);
115504}
DUCKDB_API void InitializeScanChunk(DataChunk &chunk) const
Initializes a chunk with the correct types that can be used to call Scan.
Definition duckdb.cpp:115502
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeScanChunk() [2/3]

void duckdb::ColumnDataCollection::InitializeScanChunk ( Allocator & allocator,
DataChunk & chunk ) const
115506 {
115507 chunk.Initialize(allocator, types);
115508}
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791

◆ InitializeScanChunk() [3/3]

void duckdb::ColumnDataCollection::InitializeScanChunk ( ColumnDataScanState & state,
DataChunk & chunk ) const

Initializes a chunk with the correct types for a given scan state.

115510 {
115511 D_ASSERT(!state.column_ids.empty());
115512 vector<LogicalType> chunk_types;
115513 chunk_types.reserve(state.column_ids.size());
115514 for (idx_t i = 0; i < state.column_ids.size(); i++) {
115515 auto column_idx = state.column_ids[i];
115516 D_ASSERT(column_idx < types.size());
115517 chunk_types.push_back(types[column_idx]);
115518 }
115519 chunk.Initialize(allocator->GetAllocator(), chunk_types);
115520}
Here is the call graph for this function:

◆ InitializeScan() [1/4]

void duckdb::ColumnDataCollection::InitializeScan ( ColumnDataScanState & state,
ColumnDataScanProperties properties = ColumnDataScanProperties::ALLOW_ZERO_COPY ) const

Initializes a Scan state for scanning all columns.

115453 {
115454 vector<column_t> column_ids;
115455 column_ids.reserve(types.size());
115456 for (idx_t i = 0; i < types.size(); i++) {
115457 column_ids.push_back(i);
115458 }
115459 InitializeScan(state, std::move(column_ids), properties);
115460}
DUCKDB_API void InitializeScan(ColumnDataScanState &state, ColumnDataScanProperties properties=ColumnDataScanProperties::ALLOW_ZERO_COPY) const
Initializes a Scan state for scanning all columns.
Definition duckdb.cpp:115453
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeScan() [2/4]

void duckdb::ColumnDataCollection::InitializeScan ( ColumnDataScanState & state,
vector< column_t > column_ids,
ColumnDataScanProperties properties = ColumnDataScanProperties::ALLOW_ZERO_COPY ) const

Initializes a Scan state for scanning a subset of the columns.

115463 {
115464 state.db = allocator->GetDatabase();
115465 state.chunk_index = 0;
115466 state.segment_index = 0;
115467 state.current_row_index = 0;
115468 state.next_row_index = 0;
115469 state.current_chunk_state.handles.clear();
115470 state.properties = properties;
115471 state.column_ids = std::move(column_ids);
115472}

◆ InitializeScan() [3/4]

void duckdb::ColumnDataCollection::InitializeScan ( ColumnDataParallelScanState & state,
ColumnDataScanProperties properties = ColumnDataScanProperties::ALLOW_ZERO_COPY ) const

Initialize a parallel scan over the column data collection over all columns.

115475 {
115476 InitializeScan(state.scan_state, properties);
115477}
Here is the call graph for this function:

◆ InitializeScan() [4/4]

void duckdb::ColumnDataCollection::InitializeScan ( ColumnDataParallelScanState & state,
vector< column_t > column_ids,
ColumnDataScanProperties properties = ColumnDataScanProperties::ALLOW_ZERO_COPY ) const

Initialize a parallel scan over the column data collection over a subset of the columns.

115480 {
115481 InitializeScan(state.scan_state, std::move(column_ids), properties);
115482}
Here is the call graph for this function:

◆ Scan() [1/2]

bool duckdb::ColumnDataCollection::Scan ( ColumnDataScanState & state,
DataChunk & result ) const

Scans a DataChunk from the ColumnDataCollection.

115583 {
115584 for (idx_t i = 0; i < state.column_ids.size(); i++) {
115585 D_ASSERT(result.GetTypes()[i] == types[state.column_ids[i]]);
115586 }
115587
115588 result.Reset();
115589
115590 idx_t chunk_index;
115591 idx_t segment_index;
115592 idx_t row_index;
115593 if (!NextScanIndex(state, chunk_index, segment_index, row_index)) {
115594 return false;
115595 }
115596
115597 // found a chunk to scan -> scan it
115598 auto &segment = *segments[segment_index];
115599 state.current_chunk_state.properties = state.properties;
115600 segment.ReadChunk(chunk_index, state.current_chunk_state, result, state.column_ids);
115601 result.Verify();
115602 return true;
115603}
bool NextScanIndex(ColumnDataScanState &state, idx_t &chunk_index, idx_t &segment_index, idx_t &row_index) const
Obtains the next scan index to scan from.
Definition duckdb.cpp:115522
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Scan() [2/2]

bool duckdb::ColumnDataCollection::Scan ( ColumnDataParallelScanState & state,
ColumnDataLocalScanState & lstate,
DataChunk & result ) const

Scans a DataChunk from the ColumnDataCollection.

115485 {
115486 D_ASSERT(result.GetTypes() == types);
115487 result.Reset();
115488
115489 idx_t chunk_index;
115490 idx_t segment_index;
115491 idx_t row_index;
115492 {
115493 lock_guard<mutex> l(state.lock);
115494 if (!NextScanIndex(state.scan_state, chunk_index, segment_index, row_index)) {
115495 return false;
115496 }
115497 }
115498 ScanAtIndex(state, lstate, result, chunk_index, segment_index, row_index);
115499 return true;
115500}
void ScanAtIndex(ColumnDataParallelScanState &state, ColumnDataLocalScanState &lstate, DataChunk &result, idx_t chunk_index, idx_t segment_index, idx_t row_index) const
Scans at the indices (obtained from NextScanIndex).
Definition duckdb.cpp:115569
Here is the call graph for this function:

◆ Append() [2/2]

void duckdb::ColumnDataCollection::Append ( DataChunk & new_chunk)

Append a DataChunk directly to this ColumnDataCollection - calls InitializeAppend and Append internally.

115444 {
115445 ColumnDataAppendState state;
115446 InitializeAppend(state);
115447 Append(state, input);
115448}
DUCKDB_API void Append(ColumnDataAppendState &state, DataChunk &new_chunk)
Append a DataChunk to this ColumnDataCollection using the specified append state.
Definition duckdb.cpp:115403
DUCKDB_API void InitializeAppend(ColumnDataAppendState &state)
Initializes an Append state - useful for optimizing many appends made to the same column data collect...
Definition duckdb.cpp:114753
Here is the call graph for this function:

◆ Combine()

void duckdb::ColumnDataCollection::Combine ( ColumnDataCollection & other)

Appends the other ColumnDataCollection to this, destroying the other data collection.

115644 {
115645 if (other.count == 0) {
115646 return;
115647 }
115648 if (types != other.types) {
115649 throw InternalException("Attempting to combine ColumnDataCollections with mismatching types");
115650 }
115651 this->count += other.count;
115652 this->segments.reserve(segments.size() + other.segments.size());
115653 for (auto &other_seg : other.segments) {
115654 segments.push_back(std::move(other_seg));
115655 }
115656 other.Reset();
115657 Verify();
115658}
Here is the call graph for this function:

◆ Verify()

void duckdb::ColumnDataCollection::Verify ( )
115688 {
115689#ifdef DEBUG
115690 // verify counts
115691 idx_t total_segment_count = 0;
115692 for (auto &segment : segments) {
115693 segment->Verify();
115694 total_segment_count += segment->count;
115695 }
115696 D_ASSERT(total_segment_count == this->count);
115697#endif
115698}

◆ ToString()

string duckdb::ColumnDataCollection::ToString ( ) const
115701 {
115702 DataChunk chunk;
115703 InitializeScanChunk(chunk);
115704
115705 ColumnDataScanState scan_state;
115706 InitializeScan(scan_state);
115707
115708 string result = StringUtil::Format("ColumnDataCollection - [%llu Chunks, %llu Rows]\n", ChunkCount(), Count());
115709 idx_t chunk_idx = 0;
115710 idx_t row_count = 0;
115711 while (Scan(scan_state, chunk)) {
115712 result +=
115713 StringUtil::Format("Chunk %llu - [Rows %llu - %llu]\n", chunk_idx, row_count, row_count + chunk.size()) +
115714 chunk.ToString();
115715 chunk_idx++;
115716 row_count += chunk.size();
115717 }
115718
115719 return result;
115720}
DUCKDB_API idx_t ChunkCount() const
Returns the number of data chunks present in the ColumnDataCollection.
Definition duckdb.cpp:115663
DUCKDB_API bool Scan(ColumnDataScanState &state, DataChunk &result) const
Scans a DataChunk from the ColumnDataCollection.
Definition duckdb.cpp:115583
DUCKDB_API string ToString() const
Converts this DataChunk to a printable string representation.
Definition duckdb.cpp:117003
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002

◆ Print()

void duckdb::ColumnDataCollection::Print ( ) const
115723 {
115724 Printer::Print(ToString());
115725}
static DUCKDB_API void Print(OutputStream stream, const string &str)
Print the object to the stream.
Definition duckdb.cpp:92556

◆ Reset()

void duckdb::ColumnDataCollection::Reset ( )
115727 {
115728 count = 0;
115729 segments.clear();
115730
115731 // Refreshes the ColumnDataAllocator to prevent holding on to allocated data unnecessarily
115732 allocator = make_shared_ptr<ColumnDataAllocator>(*allocator);
115733}

◆ ChunkCount()

idx_t duckdb::ColumnDataCollection::ChunkCount ( ) const

Returns the number of data chunks present in the ColumnDataCollection.

115663 {
115664 idx_t chunk_count = 0;
115665 for (auto &segment : segments) {
115666 chunk_count += segment->ChunkCount();
115667 }
115668 return chunk_count;
115669}
Here is the caller graph for this function:

◆ FetchChunk()

void duckdb::ColumnDataCollection::FetchChunk ( idx_t chunk_idx,
DataChunk & result ) const

Fetch an individual chunk from the ColumnDataCollection.

115671 {
115672 D_ASSERT(result.GetTypes() == types);
115673 D_ASSERT(chunk_idx < ChunkCount());
115674 for (auto &segment : segments) {
115675 if (chunk_idx >= segment->ChunkCount()) {
115676 chunk_idx -= segment->ChunkCount();
115677 } else {
115678 segment->FetchChunk(chunk_idx, result);
115679 return;
115680 }
115681 }
115682 throw InternalException("Failed to find chunk in ColumnDataCollection");
115683}
Here is the call graph for this function:

◆ Chunks() [1/2]

ColumnDataChunkIterationHelper duckdb::ColumnDataCollection::Chunks ( ) const

Constructs a class that can be iterated over to fetch individual chunks Iterating over this is syntactic sugar over just calling Scan

114628 {
114629 vector<column_t> column_ids;
114630 for (idx_t i = 0; i < ColumnCount(); i++) {
114631 column_ids.push_back(i);
114632 }
114633 return Chunks(column_ids);
114634}
DUCKDB_API ColumnDataChunkIterationHelper Chunks() const
Definition duckdb.cpp:114628
idx_t ColumnCount() const
The amount of columns in the ColumnDataCollection.
Definition duckdb.hpp:19006
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Chunks() [2/2]

ColumnDataChunkIterationHelper duckdb::ColumnDataCollection::Chunks ( vector< column_t > column_ids) const

Constructs a class that can be iterated over to fetch individual chunks Only the column indexes specified in the column_ids list are scanned

114636 {
114637 return ColumnDataChunkIterationHelper(*this, std::move(column_ids));
114638}

◆ Rows()

ColumnDataRowIterationHelper duckdb::ColumnDataCollection::Rows ( ) const

Constructs a class that can be iterated over to fetch individual rows Note that row iteration is slow, and the .Chunks() method should be used instead

114694 {
114695 return ColumnDataRowIterationHelper(*this);
114696}

◆ GetRows()

ColumnDataRowCollection duckdb::ColumnDataCollection::GetRows ( ) const

Returns a materialized set of all of the rows in the column data collection Note that usage of this is slow - avoid using this unless the amount of rows is small, or if you do not care about performance

115637 {
115638 return ColumnDataRowCollection(*this);
115639}

◆ ResultEquals()

bool duckdb::ColumnDataCollection::ResultEquals ( const ColumnDataCollection & left,
const ColumnDataCollection & right,
string & error_message,
bool ordered = false )
static

Compare two column data collections to another. If they are equal according to result equality rules, return true. That means null values are equal, and approx equality is used for floating point values. If they are not equal, return false and fill in the error message.

115742 {
115743 if (left.ColumnCount() != right.ColumnCount()) {
115744 error_message = StringUtil::Format("Column count mismatch (%d vs %d)", left.Count(), right.Count());
115745 return false;
115746 }
115747 if (left.Count() != right.Count()) {
115748 error_message = StringUtil::Format("Row count mismatch (%d vs %d)", left.Count(), right.Count());
115749 return false;
115750 }
115751 auto left_rows = left.GetRows();
115752 auto right_rows = right.GetRows();
115753 for (idx_t r = 0; r < left.Count(); r++) {
115754 for (idx_t c = 0; c < left.ColumnCount(); c++) {
115755 auto lvalue = left_rows.GetValue(c, r);
115756 auto rvalue = right_rows.GetValue(c, r);
115757
115758 if (!Value::DefaultValuesAreEqual(lvalue, rvalue)) {
115759 error_message =
115760 StringUtil::Format("%s <> %s (row: %lld, col: %lld)\n", lvalue.ToString(), rvalue.ToString(), r, c);
115761 break;
115762 }
115763 }
115764 if (!error_message.empty()) {
115765 if (ordered) {
115766 return false;
115767 } else {
115768 break;
115769 }
115770 }
115771 }
115772 if (!error_message.empty()) {
115773 // do an unordered comparison
115774 bool found_all = true;
115775 for (idx_t c = 0; c < left.ColumnCount(); c++) {
115776 std::unordered_multiset<Value, ValueHashFunction, ValueResultEquals> lvalues;
115777 for (idx_t r = 0; r < left.Count(); r++) {
115778 auto lvalue = left_rows.GetValue(c, r);
115779 lvalues.insert(lvalue);
115780 }
115781 for (idx_t r = 0; r < right.Count(); r++) {
115782 auto rvalue = right_rows.GetValue(c, r);
115783 auto entry = lvalues.find(rvalue);
115784 if (entry == lvalues.end()) {
115785 found_all = false;
115786 break;
115787 }
115788 lvalues.erase(entry);
115789 }
115790 if (!found_all) {
115791 break;
115792 }
115793 }
115794 if (!found_all) {
115795 return false;
115796 }
115797 error_message = string();
115798 }
115799 return true;
115800}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NextScanIndex()

bool duckdb::ColumnDataCollection::NextScanIndex ( ColumnDataScanState & state,
idx_t & chunk_index,
idx_t & segment_index,
idx_t & row_index ) const

Obtains the next scan index to scan from.

115523 {
115524 row_index = state.current_row_index = state.next_row_index;
115525 // check if we still have collections to scan
115526 if (state.segment_index >= segments.size()) {
115527 // no more data left in the scan
115528 return false;
115529 }
115530 // check within the current collection if we still have chunks to scan
115531 while (state.chunk_index >= segments[state.segment_index]->chunk_data.size()) {
115532 // exhausted all chunks for this internal data structure: move to the next one
115533 state.chunk_index = 0;
115534 state.segment_index++;
115535 state.current_chunk_state.handles.clear();
115536 if (state.segment_index >= segments.size()) {
115537 return false;
115538 }
115539 }
115540 state.next_row_index += segments[state.segment_index]->chunk_data[state.chunk_index].count;
115541 segment_index = state.segment_index;
115542 chunk_index = state.chunk_index++;
115543 return true;
115544}
Here is the caller graph for this function:

◆ PrevScanIndex()

bool duckdb::ColumnDataCollection::PrevScanIndex ( ColumnDataScanState & state,
idx_t & chunk_index,
idx_t & segment_index,
idx_t & row_index ) const

Obtains the previous scan index to scan from.

115547 {
115548 // check within the current segment if we still have chunks to scan
115549 // Note that state.chunk_index is 1-indexed, with 0 as undefined.
115550 while (state.chunk_index <= 1) {
115551 if (!state.segment_index) {
115552 return false;
115553 }
115554
115555 --state.segment_index;
115556 state.chunk_index = segments[state.segment_index]->chunk_data.size() + 1;
115557 state.current_chunk_state.handles.clear();
115558 }
115559
115560 --state.chunk_index;
115561 segment_index = state.segment_index;
115562 chunk_index = state.chunk_index - 1;
115563 state.next_row_index = state.current_row_index;
115564 state.current_row_index -= segments[state.segment_index]->chunk_data[chunk_index].count;
115565 row_index = state.current_row_index;
115566 return true;
115567}
Here is the caller graph for this function:

◆ ScanAtIndex()

void duckdb::ColumnDataCollection::ScanAtIndex ( ColumnDataParallelScanState & state,
ColumnDataLocalScanState & lstate,
DataChunk & result,
idx_t chunk_index,
idx_t segment_index,
idx_t row_index ) const

Scans at the indices (obtained from NextScanIndex).

115571 {
115572 if (segment_index != lstate.current_segment_index) {
115573 lstate.current_chunk_state.handles.clear();
115574 lstate.current_segment_index = segment_index;
115575 }
115576 auto &segment = *segments[segment_index];
115577 lstate.current_chunk_state.properties = state.scan_state.properties;
115578 segment.ReadChunk(chunk_index, lstate.current_chunk_state, result, state.scan_state.column_ids);
115579 lstate.current_row_index = row_index;
115580 result.Verify();
115581}
Here is the caller graph for this function:

◆ Seek()

bool duckdb::ColumnDataCollection::Seek ( idx_t row_idx,
ColumnDataScanState & state,
DataChunk & result ) const

Seeks to the chunk containing the row. Returns false if it is past the end. Note that the returned chunk will likely not be aligned to the given row but the scan state will provide the actual range

115605 {
115606 // Idempotency: Don't change anything if the row is already in range
115607 if (state.current_row_index <= seek_idx && seek_idx < state.next_row_index) {
115608 return true;
115609 }
115610
115611 result.Reset();
115612
115613 // Linear scan for now. We could use a current_row_index => chunk map at some point
115614 // but most use cases should be pretty local
115615 idx_t chunk_index;
115616 idx_t segment_index;
115617 idx_t row_index;
115618 while (seek_idx < state.current_row_index) {
115619 if (!PrevScanIndex(state, chunk_index, segment_index, row_index)) {
115620 return false;
115621 }
115622 }
115623 while (state.next_row_index <= seek_idx) {
115624 if (!NextScanIndex(state, chunk_index, segment_index, row_index)) {
115625 return false;
115626 }
115627 }
115628
115629 // found a chunk to scan -> scan it
115630 auto &segment = *segments[segment_index];
115631 state.current_chunk_state.properties = state.properties;
115632 segment.ReadChunk(chunk_index, state.current_chunk_state, result, state.column_ids);
115633 result.Verify();
115634 return true;
115635}
bool PrevScanIndex(ColumnDataScanState &state, idx_t &chunk_index, idx_t &segment_index, idx_t &row_index) const
Obtains the previous scan index to scan from.
Definition duckdb.cpp:115546
Here is the call graph for this function:

◆ Initialize()

void duckdb::ColumnDataCollection::Initialize ( vector< LogicalType > types)

Initialize the column data collection.

114519 {
114520 this->types = std::move(types_p);
114521 this->count = 0;
114522 this->finished_append = false;
114523 D_ASSERT(!types.empty());
114524 copy_functions.reserve(types.size());
114525 for (auto &type : types) {
114526 copy_functions.push_back(GetCopyFunction(type));
114527 }
114528}
Here is the caller graph for this function:

◆ GetHeapReferences()

vector< shared_ptr< StringHeap > > duckdb::ColumnDataCollection::GetHeapReferences ( )

Get references to the string heaps in this ColumnDataCollection.

115802 {
115803 vector<shared_ptr<StringHeap>> result(segments.size(), nullptr);
115804 for (idx_t segment_idx = 0; segment_idx < segments.size(); segment_idx++) {
115805 result[segment_idx] = segments[segment_idx]->heap;
115806 }
115807 return result;
115808}

◆ GetAllocatorType()

ColumnDataAllocatorType duckdb::ColumnDataCollection::GetAllocatorType ( ) const

Get the allocator type of this ColumnDataCollection.

115810 {
115811 return allocator->GetType();
115812}

◆ GetBufferManager()

BufferManager & duckdb::ColumnDataCollection::GetBufferManager ( ) const

Get the buffer manager of the allocator.

115814 {
115816 return allocator->GetBufferManager();
115817}
@ BUFFER_MANAGER_ALLOCATOR
Use a buffer manager to allocate large chunks of memory that vectors then use.
Definition duckdb.hpp:18799

◆ GetSegments()

const vector< unique_ptr< ColumnDataCollectionSegment > > & duckdb::ColumnDataCollection::GetSegments ( ) const

Get a vector of the segments in this ColumnDataCollection.

115819 {
115820 return segments;
115821}

◆ Serialize()

void duckdb::ColumnDataCollection::Serialize ( Serializer & serializer) const
115823 {
115824 vector<vector<Value>> values;
115825 values.resize(ColumnCount());
115826 for (auto &chunk : Chunks()) {
115827 for (idx_t c = 0; c < chunk.ColumnCount(); c++) {
115828 for (idx_t r = 0; r < chunk.size(); r++) {
115829 values[c].push_back(chunk.GetValue(c, r));
115830 }
115831 }
115832 }
115833 serializer.WriteProperty(100, "types", types);
115834 serializer.WriteProperty(101, "values", values);
115835}

◆ Deserialize()

unique_ptr< ColumnDataCollection > duckdb::ColumnDataCollection::Deserialize ( Deserializer & deserializer)
static
115837 {
115838 auto types = deserializer.ReadProperty<vector<LogicalType>>(100, "types");
115839 auto values = deserializer.ReadProperty<vector<vector<Value>>>(101, "values");
115840
115841 auto collection = make_uniq<ColumnDataCollection>(Allocator::DefaultAllocator(), types);
115842 if (values.empty()) {
115843 return collection;
115844 }
115845 DataChunk chunk;
115846 chunk.Initialize(Allocator::DefaultAllocator(), types);
115847
115848 for (idx_t r = 0; r < values[0].size(); r++) {
115849 for (idx_t c = 0; c < types.size(); c++) {
115850 chunk.SetValue(c, chunk.size(), values[c][r]);
115851 }
115852 chunk.SetCardinality(chunk.size() + 1);
115853 if (chunk.size() == STANDARD_VECTOR_SIZE) {
115854 collection->Append(chunk);
115855 chunk.Reset();
115856 }
115857 }
115858 if (chunk.size() > 0) {
115859 collection->Append(chunk);
115860 }
115861 return collection;
115862}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840

◆ CreateSegment()

void duckdb::ColumnDataCollection::CreateSegment ( )
private

Creates a new segment within the ColumnDataCollection.

114530 {
114531 segments.emplace_back(make_uniq<ColumnDataCollectionSegment>(allocator, types));
114532}
Here is the caller graph for this function:

◆ GetCopyFunction()

ColumnDataCopyFunction duckdb::ColumnDataCollection::GetCopyFunction ( const LogicalType & type)
staticprivate
115315 {
115316 ColumnDataCopyFunction result;
115317 column_data_copy_function_t function;
115318 switch (type.InternalType()) {
115319 case PhysicalType::BOOL:
115320 function = ColumnDataCopy<bool>;
115321 break;
115322 case PhysicalType::INT8:
115323 function = ColumnDataCopy<int8_t>;
115324 break;
115325 case PhysicalType::INT16:
115326 function = ColumnDataCopy<int16_t>;
115327 break;
115328 case PhysicalType::INT32:
115329 function = ColumnDataCopy<int32_t>;
115330 break;
115331 case PhysicalType::INT64:
115332 function = ColumnDataCopy<int64_t>;
115333 break;
115334 case PhysicalType::INT128:
115335 function = ColumnDataCopy<hugeint_t>;
115336 break;
115337 case PhysicalType::UINT8:
115338 function = ColumnDataCopy<uint8_t>;
115339 break;
115341 function = ColumnDataCopy<uint16_t>;
115342 break;
115344 function = ColumnDataCopy<uint32_t>;
115345 break;
115347 function = ColumnDataCopy<uint64_t>;
115348 break;
115349 case PhysicalType::UINT128:
115350 function = ColumnDataCopy<uhugeint_t>;
115351 break;
115352 case PhysicalType::FLOAT:
115353 function = ColumnDataCopy<float>;
115354 break;
115356 function = ColumnDataCopy<double>;
115357 break;
115359 function = ColumnDataCopy<interval_t>;
115360 break;
115362 function = ColumnDataCopy<string_t>;
115363 break;
115364 case PhysicalType::STRUCT: {
115365 function = ColumnDataCopyStruct;
115366 auto &child_types = StructType::GetChildTypes(type);
115367 for (auto &kv : child_types) {
115368 result.child_functions.push_back(GetCopyFunction(kv.second));
115369 }
115370 break;
115371 }
115372 case PhysicalType::LIST: {
115373 function = ColumnDataCopy<list_entry_t>;
115374 auto child_function = GetCopyFunction(ListType::GetChildType(type));
115375 result.child_functions.push_back(child_function);
115376 break;
115377 }
115378 case PhysicalType::ARRAY: {
115379 function = ColumnDataCopyArray;
115380 auto child_function = GetCopyFunction(ArrayType::GetChildType(type));
115381 result.child_functions.push_back(child_function);
115382 break;
115383 }
115384 default:
115385 throw InternalException("Unsupported type %s for ColumnDataCollection::GetCopyFunction",
115386 EnumUtil::ToString(type.InternalType()));
115387 }
115388 result.function = function;
115389 return result;
115390}
@ UINT32
Unsigned 32-bit little-endian integer.
Definition duckdb.hpp:2758
@ INTERVAL
YEAR_MONTH or DAY_TIME interval in SQL style.
Definition duckdb.hpp:2806
@ LIST
A list of some logical data type.
Definition duckdb.hpp:2813
@ UINT16
Unsigned 16-bit little-endian integer.
Definition duckdb.hpp:2752
@ INT64
Signed 64-bit little-endian integer.
Definition duckdb.hpp:2767
@ INT16
Signed 16-bit little-endian integer.
Definition duckdb.hpp:2755
@ INT32
Signed 32-bit little-endian integer.
Definition duckdb.hpp:2761
@ UINT64
Unsigned 64-bit little-endian integer.
Definition duckdb.hpp:2764
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
@ FLOAT
4-byte floating point value
Definition duckdb.hpp:2773
@ UINT8
Unsigned 8-bit little-endian integer.
Definition duckdb.hpp:2746
@ INT8
Signed 8-bit little-endian integer.
Definition duckdb.hpp:2749
@ DOUBLE
8-byte floating point value
Definition duckdb.hpp:2776

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