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

Public Types

using ZippedTuple = WindowDistinctSortTree::ZippedTuple
using ZippedElements = WindowDistinctSortTree::ZippedElements

Public Member Functions

 WindowDistinctAggregatorGlobalState (ClientContext &context, const WindowDistinctAggregator &aggregator, idx_t group_count)
optional_ptr< LocalSinkState > InitializeLocalSort (ExecutionContext &context) const
 Create a new local sort.
bool TryPrepareNextStage (WindowDistinctAggregatorLocalState &lstate)
Public Member Functions inherited from duckdb::WindowAggregatorGlobalState
 WindowAggregatorGlobalState (ClientContext &client, const WindowAggregator &aggregator_p, idx_t group_count)
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

vector< unique_ptr< ArenaAllocator > > tree_allocators
mutex lock
 Finalize guard.
atomic< WindowDistinctSortStage > stage
 Finalize stage.
idx_t total_tasks = 0
 Tasks launched.
idx_t tasks_assigned
 Tasks launched.
atomic< idx_t > tasks_completed
 Tasks landed.
vector< LogicalType > sort_types
 The aggregate arguments + partition index.
vector< idx_t > sort_cols
 Sorting operations.
unique_ptr< Sort > sort
unique_ptr< GlobalSinkState > global_sink
vector< unique_ptr< LocalSinkState > > local_sinks
 Local sort sets.
unique_ptr< ColumnDataCollection > sorted
 The resulting sorted data.
MergeSortTree< ZippedTuple > zipped_tree
 The MST with the distinct back pointers.
WindowDistinctSortTree merge_sort_tree
 The merge sort tree for the aggregate.
WindowAggregateStates levels_flat_native
 The actual window segment tree: an array of aggregate states that represent all the intermediate nodes.
vector< idx_t > levels_flat_start
 For each level, the starting location in the levels_flat_native array.
Public Attributes inherited from duckdb::WindowAggregatorGlobalState
ClientContext & client
 The client we are in.
ArenaAllocator allocator
 Global allocator.
const WindowAggregator & aggregator
 The aggregator data.
const AggregateObject aggr
 The aggregate function.
ValidityArray filter_mask
 The filtered rows in inputs.
mutex lock
 Lock for single threading.
std::atomic< idx_t > locals
 Count of local tasks.
std::atomic< idx_t > finalized
 Number of finalised states.
Public Attributes inherited from duckdb::GlobalSinkState
SinkFinalizeType state

Constructor & Destructor Documentation

◆ WindowDistinctAggregatorGlobalState()

duckdb::WindowDistinctAggregatorGlobalState::WindowDistinctAggregatorGlobalState ( ClientContext & context,
const WindowDistinctAggregator & aggregator,
idx_t group_count )
255537 : WindowAggregatorGlobalState(client, aggregator, group_count), stage(WindowDistinctSortStage::INIT),
255539 // 1: functionComputePrevIdcs(𝑖𝑛)
255540 // 2: sorted ← []
255541 // We sort the aggregate arguments and use the partition index as a tie-breaker.
255542 // TODO: Use a hash table?
255543 sort_types = aggregator.arg_types;
255544 sort_types.emplace_back(LogicalType::UBIGINT);
255545
255546 // All expressions will be precomputed for sharing, so we jsut need to reference the arguments
255547 vector<BoundOrderByNode> orders;
255548 for (const auto &type : sort_types) {
255549 auto expr = make_uniq<BoundReferenceExpression>(type, orders.size());
255550 orders.emplace_back(OrderType::ASCENDING, OrderByNullType::NULLS_FIRST, std::move(expr));
255551 sort_cols.emplace_back(sort_cols.size());
255552 }
255553
255554 sort = make_uniq<Sort>(client, orders, sort_types, sort_cols);
255555 global_sink = sort->GetGlobalSinkState(client);
255556
255557 // 6: prevIdcs ← []
255558 // 7: prevIdcs[0] ← “-”
255559 auto &prev_idcs = zipped_tree.Allocate(group_count);
255560
255561 // To handle FILTER clauses we make the missing elements
255562 // point to themselves so they won't be counted.
255563 for (idx_t i = 0; i < group_count; ++i) {
255564 prev_idcs[i] = ZippedTuple(i + 1, i);
255565 }
255566
255567 // compute space required to store aggregation states of merge sort tree
255568 // this is one aggregate state per entry per level
255569 idx_t internal_nodes = 0;
255570 levels_flat_start.push_back(internal_nodes);
255571 for (idx_t level_nr = 0; level_nr < zipped_tree.tree.size(); ++level_nr) {
255572 internal_nodes += zipped_tree.tree[level_nr].first.size();
255573 levels_flat_start.push_back(internal_nodes);
255574 }
255575 levels_flat_native.Initialize(internal_nodes);
255576
255577 merge_sort_tree.tree.reserve(zipped_tree.tree.size());
255578 for (idx_t level_nr = 0; level_nr < zipped_tree.tree.size(); ++level_nr) {
255579 auto &zipped_level = zipped_tree.tree[level_nr].first;
255580 WindowDistinctSortTree::Elements level;
255581 WindowDistinctSortTree::Offsets cascades;
255582 level.resize(zipped_level.size());
255583 merge_sort_tree.tree.emplace_back(std::move(level), std::move(cascades));
255584 }
255585}
ClientContext & client
The client we are in.
Definition duckdb.cpp:164054
const WindowAggregator & aggregator
The aggregator data.
Definition duckdb.cpp:164060
const AggregateObject aggr
The aggregate function.
Definition duckdb.cpp:164063
vector< idx_t > sort_cols
Sorting operations.
Definition duckdb.cpp:255515
WindowDistinctSortTree merge_sort_tree
The merge sort tree for the aggregate.
Definition duckdb.cpp:255526
WindowAggregateStates levels_flat_native
The actual window segment tree: an array of aggregate states that represent all the intermediate node...
Definition duckdb.cpp:255529
MergeSortTree< ZippedTuple > zipped_tree
The MST with the distinct back pointers.
Definition duckdb.cpp:255524
vector< idx_t > levels_flat_start
For each level, the starting location in the levels_flat_native array.
Definition duckdb.cpp:255531
atomic< WindowDistinctSortStage > stage
Finalize stage.
Definition duckdb.cpp:255503
atomic< idx_t > tasks_completed
Tasks landed.
Definition duckdb.cpp:255509
vector< LogicalType > sort_types
The aggregate arguments + partition index.
Definition duckdb.cpp:255512
idx_t tasks_assigned
Tasks launched.
Definition duckdb.cpp:255507
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ InitializeLocalSort()

optional_ptr< LocalSinkState > duckdb::WindowDistinctAggregatorGlobalState::InitializeLocalSort ( ExecutionContext & context) const

Create a new local sort.

255587 {
255588 lock_guard<mutex> local_sort_guard(lock);
255589 auto local_sink = sort->GetLocalSinkState(context);
255590 ++tasks_assigned;
255591 local_sinks.emplace_back(std::move(local_sink));
255592
255593 return local_sinks.back().get();
255594}
vector< unique_ptr< LocalSinkState > > local_sinks
Local sort sets.
Definition duckdb.cpp:255519
mutex lock
Finalize guard.
Definition duckdb.cpp:255501

◆ TryPrepareNextStage()

bool duckdb::WindowDistinctAggregatorGlobalState::TryPrepareNextStage ( WindowDistinctAggregatorLocalState & lstate)
255746 {
255747 lock_guard<mutex> stage_guard(lock);
255748
255749 switch (stage.load()) {
255750 case WindowDistinctSortStage::INIT:
255751 total_tasks = local_sinks.size();
255752 tasks_assigned = 0;
255753 tasks_completed = 0;
255754 lstate.stage = stage = WindowDistinctSortStage::COMBINE;
255755 lstate.block_idx = tasks_assigned++;
255756 return true;
255757 case WindowDistinctSortStage::COMBINE:
255758 if (tasks_assigned < total_tasks) {
255759 lstate.stage = WindowDistinctSortStage::COMBINE;
255760 lstate.block_idx = tasks_assigned++;
255761 return true;
255762 } else if (tasks_completed < tasks_assigned) {
255763 return false;
255764 }
255765 // All combines are done, so move on to materialising the sorted data (1 task)
255766 total_tasks = 1;
255767 tasks_completed = 0;
255768 tasks_assigned = 0;
255769 lstate.stage = stage = WindowDistinctSortStage::FINALIZE;
255770 lstate.block_idx = tasks_assigned++;
255771 return true;
255772 case WindowDistinctSortStage::FINALIZE:
255774 // Wait for the single task to finish
255775 return false;
255776 }
255777 // Move on to building the tree in parallel
255778 total_tasks = local_sinks.size();
255779 tasks_completed = 0;
255780 tasks_assigned = 0;
255781 lstate.stage = stage = WindowDistinctSortStage::SORTED;
255782 lstate.block_idx = tasks_assigned++;
255783 return true;
255784 case WindowDistinctSortStage::SORTED:
255785 if (tasks_assigned < total_tasks) {
255786 lstate.stage = WindowDistinctSortStage::SORTED;
255787 lstate.block_idx = tasks_assigned++;
255788 return true;
255789 } else if (tasks_completed < tasks_assigned) {
255790 lstate.stage = WindowDistinctSortStage::FINISHED;
255791 // Sleep while other tasks finish
255792 return false;
255793 }
255794 break;
255795 default:
255796 break;
255797 }
255798
255799 lstate.stage = stage = WindowDistinctSortStage::FINISHED;
255800
255801 return true;
255802}
idx_t total_tasks
Tasks launched.
Definition duckdb.cpp:255505

Member Data Documentation

◆ tree_allocators

vector<unique_ptr<ArenaAllocator> > duckdb::WindowDistinctAggregatorGlobalState::tree_allocators
mutable

The tree allocators. We need to hold onto them for the tree lifetime, not the lifetime of the local state that constructed part of the tree


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