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::HashedSortGlobalSinkState Class Reference
Inheritance diagram for duckdb::HashedSortGlobalSinkState:
Collaboration diagram for duckdb::HashedSortGlobalSinkState:

Public Types

using HashGroupPtr = unique_ptr<HashedSortGroup>
using Orders = vector<BoundOrderByNode>
using Types = vector<LogicalType>
using GroupingPartition = unique_ptr<RadixPartitionedTupleData>
using GroupingAppend = unique_ptr<PartitionedTupleDataAppendState>

Public Member Functions

 HashedSortGlobalSinkState (ClientContext &client, const HashedSort &hashed_sort)
unique_ptr< RadixPartitionedTupleData > CreatePartition (idx_t new_bits) const
void SyncPartitioning (const HashedSortGlobalSinkState &other)
void UpdateLocalPartition (GroupingPartition &local_partition, GroupingAppend &partition_append)
void CombineLocalPartition (GroupingPartition &local_partition, GroupingAppend &local_append)
ProgressData GetSinkProgress (ClientContext &context, const ProgressData source_progress) const
Public Member Functions inherited from duckdb::GlobalSinkState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
virtual idx_t MaxThreads (idx_t source_max_threads)
Public Member Functions inherited from duckdb::StateWithBlockableTasks
unique_lock< mutex > Lock ()
void PreventBlocking (const unique_lock< mutex > &guard)
bool BlockTask (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
 Add a task to 'blocked_tasks' before returning SourceResultType::BLOCKED (must hold the lock).
bool CanBlock (const unique_lock< mutex > &guard) const
bool UnblockTasks (const unique_lock< mutex > &guard)
 Unblock all tasks (must hold the lock).
SinkResultType BlockSink (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
SourceResultType BlockSource (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
void VerifyLock (const unique_lock< mutex > &guard) const

Public Attributes

ClientContext & client
 System and query state.
const HashedSort & hashed_sort
BufferManager & buffer_manager
Allocator & allocator
mutex lock
GroupingPartition grouping_data
shared_ptr< TupleDataLayout > grouping_types_ptr
 Payload plus hash column.
idx_t fixed_bits
 The number of radix bits if this partition is being synced with another.
vector< HashGroupPtr > hash_groups
idx_t max_bits
atomic< idx_t > count
Public Attributes inherited from duckdb::GlobalSinkState
SinkFinalizeType state

Private Member Functions

void Rehash (idx_t cardinality)
void SyncLocalPartition (GroupingPartition &local_partition, GroupingAppend &local_append)

Constructor & Destructor Documentation

◆ HashedSortGlobalSinkState()

duckdb::HashedSortGlobalSinkState::HashedSortGlobalSinkState ( ClientContext & client,
const HashedSort & hashed_sort )
101880 : client(client), hashed_sort(hashed_sort), buffer_manager(BufferManager::GetBufferManager(client)),
101881 allocator(Allocator::Get(client)), fixed_bits(0), max_bits(1), count(0) {
101882 const auto memory_per_thread = PhysicalOperator::GetMaxThreadMemory(client);
101883 const auto thread_pages = PreviousPowerOfTwo(memory_per_thread / (4 * buffer_manager.GetBlockAllocSize()));
101884 while (max_bits < 8 && (thread_pages >> max_bits) > 1) {
101885 ++max_bits;
101886 }
101887
101888 grouping_types_ptr = make_shared_ptr<TupleDataLayout>();
101889 auto &payload_types = hashed_sort.payload_types;
101890 auto types = payload_types;
101891 types.push_back(LogicalType::HASH);
101892 grouping_types_ptr->Initialize(types, TupleDataValidityType::CAN_HAVE_NULL_VALUES);
101893 Rehash(hashed_sort.estimated_cardinality);
101894}
idx_t fixed_bits
The number of radix bits if this partition is being synced with another.
Definition duckdb.cpp:101865
shared_ptr< TupleDataLayout > grouping_types_ptr
Payload plus hash column.
Definition duckdb.cpp:101863
ClientContext & client
System and query state.
Definition duckdb.cpp:101854
static idx_t GetMaxThreadMemory(ClientContext &context)
The maximum amount of memory the operator should use per thread.
Definition duckdb.cpp:201588

Member Function Documentation

◆ CreatePartition()

unique_ptr< RadixPartitionedTupleData > duckdb::HashedSortGlobalSinkState::CreatePartition ( idx_t new_bits) const
101896 {
101897 auto &payload_types = hashed_sort.payload_types;
101898 const auto hash_col_idx = payload_types.size();
101899 return make_uniq<RadixPartitionedTupleData>(buffer_manager, grouping_types_ptr, MemoryTag::WINDOW, new_bits,
101900 hash_col_idx);
101901}

◆ SyncPartitioning()

void duckdb::HashedSortGlobalSinkState::SyncPartitioning ( const HashedSortGlobalSinkState & other)
101958 {
101959 fixed_bits = other.grouping_data ? other.grouping_data->GetRadixBits() : 0;
101960
101961 const auto old_bits = grouping_data ? grouping_data->GetRadixBits() : 0;
101962 if (fixed_bits != old_bits) {
101963 grouping_data = CreatePartition(fixed_bits);
101964 }
101965}

◆ UpdateLocalPartition()

void duckdb::HashedSortGlobalSinkState::UpdateLocalPartition ( GroupingPartition & local_partition,
GroupingAppend & partition_append )
101940 {
101941 // Make sure grouping_data doesn't change under us.
101942 lock_guard<mutex> guard(lock);
101943
101944 if (!local_partition) {
101945 local_partition = CreatePartition(grouping_data->GetRadixBits());
101946 partition_append = make_uniq<PartitionedTupleDataAppendState>();
101947 local_partition->InitializeAppendState(*partition_append);
101948 return;
101949 }
101950
101951 // Grow the groups if they are too big
101952 Rehash(count);
101953
101954 // Sync local partition to have the same bit count
101955 SyncLocalPartition(local_partition, partition_append);
101956}

◆ CombineLocalPartition()

void duckdb::HashedSortGlobalSinkState::CombineLocalPartition ( GroupingPartition & local_partition,
GroupingAppend & local_append )
101968 {
101969 if (!local_partition) {
101970 return;
101971 }
101972 local_partition->FlushAppendState(*local_append);
101973
101974 // Make sure grouping_data doesn't change under us.
101975 // Combine has an internal mutex, so this is single-threaded anyway.
101976 lock_guard<mutex> guard(lock);
101977 SyncLocalPartition(local_partition, local_append);
101978 fixed_bits = true;
101979
101980 // We now know the number of hash_groups (some may be empty)
101981 auto &groups = local_partition->GetPartitions();
101982 if (hash_groups.empty()) {
101983 hash_groups.resize(groups.size());
101984 }
101985
101986 // Create missing HashedSortGroups inside the mutex
101987 for (idx_t group_idx = 0; group_idx < groups.size(); ++group_idx) {
101988 auto &hash_group = hash_groups[group_idx];
101989 if (hash_group) {
101990 continue;
101991 }
101992
101993 auto &group_data = groups[group_idx];
101994 if (group_data->Count()) {
101995 hash_group = make_uniq<HashedSortGroup>(client, *hashed_sort.sort, group_idx);
101996 }
101997 }
101998
101999 // Combine the thread data into the global data
102000 grouping_data->Combine(*local_partition);
102001}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ GetSinkProgress()

ProgressData duckdb::HashedSortGlobalSinkState::GetSinkProgress ( ClientContext & context,
const ProgressData source_progress ) const
102003 {
102004 ProgressData result;
102005 result.done = source.done / 2;
102006 result.total = source.total;
102007 result.invalid = source.invalid;
102008
102009 // Sort::GetSinkProgress assumes that there is only 1 sort.
102010 // So we just use it to figure out how many rows have been sorted.
102011 const ProgressData zero_progress;
102012 lock_guard<mutex> guard(lock);
102013 const auto &sort = hashed_sort.sort;
102014 for (auto &hash_group : hash_groups) {
102015 if (!hash_group || !hash_group->sort_global) {
102016 continue;
102017 }
102018
102019 const auto group_progress = sort->GetSinkProgress(client, *hash_group->sort_global, zero_progress);
102020 result.done += group_progress.done;
102021 result.invalid = result.invalid || group_progress.invalid;
102022 }
102023
102024 return result;
102025}
void sort(InputArray src, OutputArray dst, int flags)

◆ Rehash()

void duckdb::HashedSortGlobalSinkState::Rehash ( idx_t cardinality)
private
101903 {
101904 // Have we started to combine? Then just live with it.
101905 if (fixed_bits) {
101906 return;
101907 }
101908 // Is the average partition size too large?
101909 const idx_t partition_size = DEFAULT_ROW_GROUP_SIZE;
101910 const auto bits = grouping_data ? grouping_data->GetRadixBits() : 0;
101911 auto new_bits = bits ? bits : 4;
101912 while (new_bits < max_bits && (cardinality / RadixPartitioning::NumberOfPartitions(new_bits)) > partition_size) {
101913 ++new_bits;
101914 }
101915
101916 // Repartition the grouping data
101917 if (new_bits != bits) {
101918 grouping_data = CreatePartition(new_bits);
101919 }
101920}
static constexpr idx_t NumberOfPartitions(idx_t radix_bits)
The number of partitions for a given number of radix bits.
Definition duckdb.cpp:93425

◆ SyncLocalPartition()

void duckdb::HashedSortGlobalSinkState::SyncLocalPartition ( GroupingPartition & local_partition,
GroupingAppend & local_append )
private
101922 {
101923 // We are done if the local_partition is right sized.
101924 const auto new_bits = grouping_data->GetRadixBits();
101925 if (local_partition->GetRadixBits() == new_bits) {
101926 return;
101927 }
101928
101929 // If the local partition is now too small, flush it and reallocate
101930 auto new_partition = CreatePartition(new_bits);
101931 local_partition->FlushAppendState(*local_append);
101932 local_partition->Repartition(client, *new_partition);
101933
101934 local_partition = std::move(new_partition);
101935 local_append = make_uniq<PartitionedTupleDataAppendState>();
101936 local_partition->InitializeAppendState(*local_append);
101937}

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