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

PartitionedColumnData represents partitioned columnar data, which serves as an interface for different types of partitioning, e.g., radix, hive. More...

#include <duckdb.hpp>

Inheritance diagram for duckdb::PartitionedColumnData:
Collaboration diagram for duckdb::PartitionedColumnData:

Public Member Functions

unique_ptr< PartitionedColumnData > CreateShared ()
void InitializeAppendState (PartitionedColumnDataAppendState &state) const
 Initializes a local state for parallel partitioning that can be merged into this PartitionedColumnData.
void Append (PartitionedColumnDataAppendState &state, DataChunk &input)
 Appends a DataChunk to this PartitionedColumnData.
void FlushAppendState (PartitionedColumnDataAppendState &state)
 Flushes any remaining data in the append state into this PartitionedColumnData.
void Combine (PartitionedColumnData &other)
 Combine another PartitionedColumnData into this PartitionedColumnData.
vector< unique_ptr< ColumnDataCollection > > & GetPartitions ()
 Get the partitions in this PartitionedColumnData.
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Protected Member Functions

virtual idx_t BufferSize () const
 Size of the buffers in the append states for this type of partitioning (default 128).
virtual void InitializeAppendStateInternal (PartitionedColumnDataAppendState &state) const
 Initialize a PartitionedColumnDataAppendState for this type of partitioning (optional).
virtual void ComputePartitionIndices (PartitionedColumnDataAppendState &state, DataChunk &input)
 Compute the partition indices for this type of partitioning for the input DataChunk and store them in the partition_data of the local state. If this type creates partitions on the fly (for, e.g., hive), this function is also in charge of creating new partitions and mapping the input data to a partition index.
virtual idx_t MaxPartitionIndex () const
 Maximum partition index (optional).
 PartitionedColumnData (PartitionedColumnDataType type, ClientContext &context, vector< LogicalType > types)
 PartitionedColumnData can only be instantiated by derived classes.
 PartitionedColumnData (const PartitionedColumnData &other)
idx_t HalfBufferSize () const
 If the buffer is half full, we append to the partition.
void CreateAllocator ()
 Create a new shared allocator.
bool UseFixedSizeMap () const
 Whether to use fixed size map or regular map.
void BuildPartitionSel (PartitionedColumnDataAppendState &state, const idx_t append_count) const
 Builds a selection vector in the Append state for the partitions.
template<bool fixed>
void AppendInternal (PartitionedColumnDataAppendState &state, DataChunk &input)
 Appends a DataChunk to this PartitionedColumnData.
unique_ptr< ColumnDataCollection > CreatePartitionCollection (idx_t partition_index) const
 Create a collection for a specific a partition.
unique_ptr< DataChunk > CreatePartitionBuffer () const
 Create a DataChunk used for buffering appends to the partition.

Static Protected Member Functions

template<bool fixed>
static void BuildPartitionSel (PartitionedColumnDataAppendState &state, const idx_t append_count)

Protected Attributes

PartitionedColumnDataType type
ClientContext & context
vector< LogicalType > types
mutex lock
shared_ptr< PartitionColumnDataAllocators > allocators
vector< unique_ptr< ColumnDataCollection > > partitions

Detailed Description

PartitionedColumnData represents partitioned columnar data, which serves as an interface for different types of partitioning, e.g., radix, hive.

Constructor & Destructor Documentation

◆ ~PartitionedColumnData()

duckdb::PartitionedColumnData::~PartitionedColumnData ( )
virtual
116390 {
116391}

◆ PartitionedColumnData() [1/2]

duckdb::PartitionedColumnData::PartitionedColumnData ( PartitionedColumnDataType type,
ClientContext & context,
vector< LogicalType > types )
protected

PartitionedColumnData can only be instantiated by derived classes.

116373 : type(type_p), context(context_p), types(std::move(types_p)),
116374 allocators(make_shared_ptr<PartitionColumnDataAllocators>()) {
116375}
Here is the caller graph for this function:

◆ PartitionedColumnData() [2/2]

duckdb::PartitionedColumnData::PartitionedColumnData ( const PartitionedColumnData & other)
protected
116378 : type(other.type), context(other.context), types(other.types), allocators(other.allocators) {
116379}

Member Function Documentation

◆ CreateShared()

unique_ptr< PartitionedColumnData > duckdb::PartitionedColumnData::CreateShared ( )
116381 {
116382 switch (type) {
116384 return make_uniq<RadixPartitionedColumnData>(Cast<RadixPartitionedColumnData>());
116385 default:
116386 throw NotImplementedException("CreateShared for this type of PartitionedColumnData");
116387 }
116388}
@ RADIX
Radix partitioning on a hash column.
Definition duckdb.hpp:47014

◆ InitializeAppendState()

void duckdb::PartitionedColumnData::InitializeAppendState ( PartitionedColumnDataAppendState & state) const

Initializes a local state for parallel partitioning that can be merged into this PartitionedColumnData.

116393 {
116394 state.partition_sel.Initialize();
116395 state.slice_chunk.Initialize(BufferAllocator::Get(context), types);
116397}
virtual void InitializeAppendStateInternal(PartitionedColumnDataAppendState &state) const
Initialize a PartitionedColumnDataAppendState for this type of partitioning (optional).
Definition duckdb.hpp:47053
Here is the call graph for this function:

◆ Append()

void duckdb::PartitionedColumnData::Append ( PartitionedColumnDataAppendState & state,
DataChunk & input )

Appends a DataChunk to this PartitionedColumnData.

116409 {
116410 // Compute partition indices and store them in state.partition_indices
116411 ComputePartitionIndices(state, input);
116412
116413 // Build the selection vector for the partitions
116414 BuildPartitionSel(state, input.size());
116415
116416 // Early out: check if everything belongs to a single partition
116417 const auto partition_index = state.GetPartitionIndexIfSinglePartition(UseFixedSizeMap());
116418 if (partition_index.IsValid()) {
116419 auto &partition = *partitions[partition_index.GetIndex()];
116420 auto &partition_append_state = *state.partition_append_states[partition_index.GetIndex()];
116421 partition.Append(partition_append_state, input);
116422 return;
116423 }
116424
116425 if (UseFixedSizeMap()) {
116426 AppendInternal<true>(state, input);
116427 } else {
116428 AppendInternal<false>(state, input);
116429 }
116430}
virtual void ComputePartitionIndices(PartitionedColumnDataAppendState &state, DataChunk &input)
Compute the partition indices for this type of partitioning for the input DataChunk and store them in...
Definition duckdb.hpp:47058
void BuildPartitionSel(PartitionedColumnDataAppendState &state, const idx_t append_count) const
Builds a selection vector in the Append state for the partitions.
Definition duckdb.cpp:116432
void AppendInternal(PartitionedColumnDataAppendState &state, DataChunk &input)
Appends a DataChunk to this PartitionedColumnData.
Definition duckdb.cpp:116503
bool UseFixedSizeMap() const
Whether to use fixed size map or regular map.
Definition duckdb.cpp:116399
int partition(const std::vector< _Tp > &_vec, std::vector< int > &labels, _EqPredicate predicate=_EqPredicate())
Here is the call graph for this function:

◆ FlushAppendState()

void duckdb::PartitionedColumnData::FlushAppendState ( PartitionedColumnDataAppendState & state)

Flushes any remaining data in the append state into this PartitionedColumnData.

116546 {
116547 for (idx_t i = 0; i < state.partition_buffers.size(); i++) {
116548 if (!state.partition_buffers[i]) {
116549 continue;
116550 }
116551 auto &partition_buffer = *state.partition_buffers[i];
116552 if (partition_buffer.size() > 0) {
116553 partitions[i]->Append(partition_buffer);
116554 partition_buffer.Reset();
116555 }
116556 }
116557}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Combine()

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

Combine another PartitionedColumnData into this PartitionedColumnData.

116559 {
116560 // Now combine the state's partitions into this
116561 lock_guard<mutex> guard(lock);
116562
116563 if (partitions.empty()) {
116564 // This is the first merge, we just copy them over
116565 partitions = std::move(other.partitions);
116566 } else {
116567 D_ASSERT(partitions.size() == other.partitions.size());
116568 // Combine the append state's partitions into this PartitionedColumnData
116569 for (idx_t i = 0; i < other.partitions.size(); i++) {
116570 if (!other.partitions[i]) {
116571 continue;
116572 }
116573 if (!partitions[i]) {
116574 partitions[i] = std::move(other.partitions[i]);
116575 } else {
116576 partitions[i]->Combine(*other.partitions[i]);
116577 }
116578 }
116579 }
116580}
Here is the call graph for this function:

◆ GetPartitions()

vector< unique_ptr< ColumnDataCollection > > & duckdb::PartitionedColumnData::GetPartitions ( )

Get the partitions in this PartitionedColumnData.

116582 {
116583 return partitions;
116584}

◆ BufferSize()

virtual idx_t duckdb::PartitionedColumnData::BufferSize ( ) const
inlineprotectedvirtual

Size of the buffers in the append states for this type of partitioning (default 128).

Reimplemented in duckdb::RadixPartitionedColumnData.

47049 {
47050 return MinValue<idx_t>(128, STANDARD_VECTOR_SIZE);
47051 }
Here is the caller graph for this function:

◆ InitializeAppendStateInternal()

virtual void duckdb::PartitionedColumnData::InitializeAppendStateInternal ( PartitionedColumnDataAppendState & state) const
inlineprotectedvirtual

Initialize a PartitionedColumnDataAppendState for this type of partitioning (optional).

Reimplemented in duckdb::RadixPartitionedColumnData.

47053 {
47054 }
Here is the caller graph for this function:

◆ ComputePartitionIndices()

virtual void duckdb::PartitionedColumnData::ComputePartitionIndices ( PartitionedColumnDataAppendState & state,
DataChunk & input )
inlineprotectedvirtual

Compute the partition indices for this type of partitioning for the input DataChunk and store them in the partition_data of the local state. If this type creates partitions on the fly (for, e.g., hive), this function is also in charge of creating new partitions and mapping the input data to a partition index.

Reimplemented in duckdb::HivePartitionedColumnData, and duckdb::RadixPartitionedColumnData.

47058 {
47059 throw NotImplementedException("ComputePartitionIndices for this type of PartitionedColumnData");
47060 }
Here is the caller graph for this function:

◆ MaxPartitionIndex()

virtual idx_t duckdb::PartitionedColumnData::MaxPartitionIndex ( ) const
inlineprotectedvirtual

Maximum partition index (optional).

Reimplemented in duckdb::RadixPartitionedColumnData.

47064 {
47066 }
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117
Here is the caller graph for this function:

◆ HalfBufferSize()

idx_t duckdb::PartitionedColumnData::HalfBufferSize ( ) const
inlineprotected

If the buffer is half full, we append to the partition.

47074 {
47075 D_ASSERT(IsPowerOfTwo(BufferSize()));
47076 return BufferSize() / 2;
47077 }
virtual idx_t BufferSize() const
Size of the buffers in the append states for this type of partitioning (default 128).
Definition duckdb.hpp:47049
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateAllocator()

void duckdb::PartitionedColumnData::CreateAllocator ( )
protected

Create a new shared allocator.

116586 {
116587 allocators->allocators.emplace_back(make_shared_ptr<ColumnDataAllocator>(BufferManager::GetBufferManager(context)));
116588 allocators->allocators.back()->MakeShared();
116589}

◆ UseFixedSizeMap()

bool duckdb::PartitionedColumnData::UseFixedSizeMap ( ) const
protected

Whether to use fixed size map or regular map.

116399 {
116400 return MaxPartitionIndex() < PartitionedTupleDataAppendState::MAP_THRESHOLD;
116401}
virtual idx_t MaxPartitionIndex() const
Maximum partition index (optional).
Definition duckdb.hpp:47064
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildPartitionSel() [1/2]

void duckdb::PartitionedColumnData::BuildPartitionSel ( PartitionedColumnDataAppendState & state,
const idx_t append_count ) const
protected

Builds a selection vector in the Append state for the partitions.

  • returns true if everything belongs to the same partition - stores partition index in single_partition_idx
116432 {
116433 if (UseFixedSizeMap()) {
116434 BuildPartitionSel<true>(state, append_count);
116435 } else {
116436 BuildPartitionSel<false>(state, append_count);
116437 }
116438}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildPartitionSel() [2/2]

template<bool fixed>
void duckdb::PartitionedColumnData::BuildPartitionSel ( PartitionedColumnDataAppendState & state,
const idx_t append_count )
staticprotected
116456 {
116457 using GETTER = TemplatedMapGetter<list_entry_t, fixed>;
116458 auto &partition_entries = state.GetMap<fixed>();
116459 partition_entries.clear();
116460 const auto partition_indices = FlatVector::GetData<idx_t>(state.partition_indices);
116461 switch (state.partition_indices.GetVectorType()) {
116462 case VectorType::FLAT_VECTOR:
116463 for (idx_t i = 0; i < append_count; i++) {
116464 const auto &partition_index = partition_indices[i];
116465 auto partition_entry = partition_entries.find(partition_index);
116466 if (partition_entry == partition_entries.end()) {
116467 partition_entries[partition_index] = list_entry_t(0, 1);
116468 } else {
116469 GETTER::GetValue(partition_entry).length++;
116470 }
116471 }
116472 break;
116473 case VectorType::CONSTANT_VECTOR:
116474 partition_entries[partition_indices[0]] = list_entry_t(0, append_count);
116475 break;
116476 default:
116477 throw InternalException("Unexpected VectorType in PartitionedTupleData::Append");
116478 }
116479
116480 // Early out: check if everything belongs to a single partition
116481 if (partition_entries.size() == 1) {
116482 return;
116483 }
116484
116485 // Compute offsets from the counts
116486 idx_t offset = 0;
116487 for (auto it = partition_entries.begin(); it != partition_entries.end(); ++it) {
116488 auto &partition_entry = GETTER::GetValue(it);
116489 partition_entry.offset = offset;
116490 offset += partition_entry.length;
116491 }
116492
116493 // Now initialize a single selection vector that acts as a selection vector for every partition
116494 auto &partition_sel = state.partition_sel;
116495 for (idx_t i = 0; i < append_count; i++) {
116496 const auto &partition_index = partition_indices[i];
116497 auto &partition_offset = partition_entries[partition_index].offset;
116498 partition_sel[partition_offset++] = UnsafeNumericCast<sel_t>(i);
116499 }
116500}

◆ AppendInternal()

template<bool fixed>
void duckdb::PartitionedColumnData::AppendInternal ( PartitionedColumnDataAppendState & state,
DataChunk & input )
protected

Appends a DataChunk to this PartitionedColumnData.

116503 {
116504 using GETTER = TemplatedMapGetter<list_entry_t, fixed>;
116505 const auto &partition_entries = state.GetMap<fixed>();
116506
116507 // Loop through the partitions to append the new data to the partition buffers, and flush the buffers if necessary
116508 SelectionVector partition_sel;
116509 for (auto it = partition_entries.begin(); it != partition_entries.end(); ++it) {
116510 const auto &partition_index = GETTER::GetKey(it);
116511
116512 // Partition, buffer, and append state for this partition index
116513 auto &partition = *partitions[partition_index];
116514 auto &partition_buffer = *state.partition_buffers[partition_index];
116515 auto &partition_append_state = *state.partition_append_states[partition_index];
116516
116517 // Length and offset into the selection vector for this chunk, for this partition
116518 const auto &partition_entry = GETTER::GetValue(it);
116519 const auto &partition_length = partition_entry.length;
116520 const auto partition_offset = partition_entry.offset - partition_length;
116521
116522 // Create a selection vector for this partition using the offset into the single selection vector
116523 partition_sel.Initialize(state.partition_sel.data() + partition_offset);
116524
116525 if (partition_length >= HalfBufferSize()) {
116526 // Slice the input chunk using the selection vector
116527 state.slice_chunk.Reset();
116528 state.slice_chunk.Slice(input, partition_sel, partition_length);
116529
116530 // Append it to the partition directly
116531 partition.Append(partition_append_state, state.slice_chunk);
116532 } else {
116533 // Append the input chunk to the partition buffer using the selection vector
116534 partition_buffer.Append(input, false, &partition_sel, partition_length);
116535
116536 if (partition_buffer.size() >= HalfBufferSize()) {
116537 // Next batch won't fit in the buffer, flush it to the partition
116538 partition.Append(partition_append_state, partition_buffer);
116539 partition_buffer.Reset();
116540 partition_buffer.SetCapacity(BufferSize());
116541 }
116542 }
116543 }
116544}
idx_t HalfBufferSize() const
If the buffer is half full, we append to the partition.
Definition duckdb.hpp:47074
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePartitionCollection()

unique_ptr< ColumnDataCollection > duckdb::PartitionedColumnData::CreatePartitionCollection ( idx_t partition_index) const
inlineprotected

Create a collection for a specific a partition.

47091 {
47092 return make_uniq<ColumnDataCollection>(allocators->allocators[partition_index], types);
47093 }
Here is the caller graph for this function:

◆ CreatePartitionBuffer()

unique_ptr< DataChunk > duckdb::PartitionedColumnData::CreatePartitionBuffer ( ) const
protected

Create a DataChunk used for buffering appends to the partition.

116403 {
116404 auto result = make_uniq<DataChunk>();
116405 result->Initialize(BufferAllocator::Get(context), types, BufferSize());
116406 return result;
116407}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cast() [1/2]

template<class TARGET>
TARGET & duckdb::PartitionedColumnData::Cast ( )
inline
47108 {
47109 DynamicCastCheck<TARGET>(this);
47110 return reinterpret_cast<TARGET &>(*this);
47111 }

◆ Cast() [2/2]

template<class TARGET>
const TARGET & duckdb::PartitionedColumnData::Cast ( ) const
inline
47113 {
47114 DynamicCastCheck<TARGET>(this);
47115 return reinterpret_cast<const TARGET &>(*this);
47116 }

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