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::WindowMergeSortTree Class Referenceabstract
Inheritance diagram for duckdb::WindowMergeSortTree:
Collaboration diagram for duckdb::WindowMergeSortTree:

Public Types

using GlobalSortStatePtr = unique_ptr<GlobalSinkState>
using LocalSortStatePtr = unique_ptr<LocalSinkState>
using MergeSortTree32 = MergeSortTree<uint32_t, uint32_t>
using MergeSortTree64 = MergeSortTree<uint64_t, uint64_t>

Public Member Functions

 WindowMergeSortTree (ClientContext &context, const vector< BoundOrderByNode > &orders, const vector< column_t > &order_idx, const idx_t count, bool unique=false)
virtual unique_ptr< LocalSinkState > GetLocalState (ExecutionContext &context)=0
optional_ptr< LocalSinkState > InitializeLocalSort (ExecutionContext &context) const
 Make a local sort for a thread.
virtual void Finished ()
 Thread-safe post-sort cleanup.
bool TryPrepareSortStage (WindowMergeSortTreeLocalState &lstate)
 Sort state machine.
void Build ()
 Build the MST in parallel from the sorted data.

Public Attributes

const vector< column_t > order_idx
 The column indices for sorting.
vector< LogicalType > scan_types
 The sorted data schema.
vector< idx_t > scan_cols
vector< idx_t > key_cols
 The sort key columns.
unique_ptr< Sort > sort
 The sort specification.
GlobalSortStatePtr global_sink
 The sorted data.
unique_ptr< ColumnDataCollection > sorted
 The resulting sorted data.
mutex lock
 Finalize guard.
vector< LocalSortStatePtr > local_sinks
 Local sort set.
atomic< WindowMergeSortStage > build_stage
 Finalize stage.
idx_t total_tasks = 0
 Tasks launched.
idx_t tasks_assigned = 0
 Tasks launched.
atomic< idx_t > tasks_completed
 Tasks landed.
unique_ptr< MergeSortTree32 > mst32
unique_ptr< MergeSortTree64 > mst64

Protected Member Functions

virtual idx_t MeasurePayloadBlocks ()

Constructor & Destructor Documentation

◆ WindowMergeSortTree()

duckdb::WindowMergeSortTree::WindowMergeSortTree ( ClientContext & context,
const vector< BoundOrderByNode > & orders,
const vector< column_t > & order_idx,
const idx_t count,
bool unique = false )
256370 : order_idx(order_idx), build_stage(WindowMergeSortStage::INIT), tasks_completed(0) {
256371 // Sort the unfiltered indices by the orders
256372 const auto force_external = ClientConfig::GetConfig(client).force_external;
256373 LogicalType index_type;
256374 if (count < std::numeric_limits<uint32_t>::max() && !force_external) {
256375 index_type = LogicalType::INTEGER;
256376 mst32 = make_uniq<MergeSortTree32>();
256377 } else {
256378 index_type = LogicalType::BIGINT;
256379 mst64 = make_uniq<MergeSortTree64>();
256380 }
256381
256382 vector<BoundOrderByNode> orders;
256383 for (const auto &order_p : orders_p) {
256384 auto order = order_p.Copy();
256385 const auto &type = order.expression->return_type;
256386 scan_types.emplace_back(type);
256387 order.expression = make_uniq<BoundReferenceExpression>(type, orders.size());
256388 orders.emplace_back(std::move(order));
256389 scan_cols.emplace_back(scan_cols.size());
256390 key_cols.emplace_back(key_cols.size());
256391 }
256392
256393 // Also track the index type
256394 scan_types.emplace_back(index_type);
256395 scan_cols.emplace_back(scan_cols.size());
256396
256397 // If the caller wants disambiguation, also sort by the index column
256398 if (unique) {
256399 auto unique_expr = make_uniq<BoundReferenceExpression>(scan_types.back(), orders.size());
256400 const auto order_type = OrderType::ASCENDING;
256401 const auto order_by_type = OrderByNullType::NULLS_LAST;
256402 orders.emplace_back(order_type, order_by_type, std::move(unique_expr));
256403 key_cols.emplace_back(key_cols.size());
256404 }
256405
256406 sort = make_uniq<Sort>(client, orders, scan_types, scan_cols);
256407
256408 global_sink = sort->GetGlobalSinkState(client);
256409}
atomic< WindowMergeSortStage > build_stage
Finalize stage.
Definition duckdb.cpp:60235
vector< LogicalType > scan_types
The sorted data schema.
Definition duckdb.cpp:60220
atomic< idx_t > tasks_completed
Tasks landed.
Definition duckdb.cpp:60241
vector< idx_t > key_cols
The sort key columns.
Definition duckdb.cpp:60223
unique_ptr< Sort > sort
The sort specification.
Definition duckdb.cpp:60225
const vector< column_t > order_idx
The column indices for sorting.
Definition duckdb.cpp:60218
GlobalSortStatePtr global_sink
The sorted data.
Definition duckdb.cpp:60227
float index_type

Member Function Documentation

◆ InitializeLocalSort()

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

Make a local sort for a thread.

256411 {
256412 lock_guard<mutex> local_sort_guard(lock);
256413 auto local_sink = sort->GetLocalSinkState(context);
256414 local_sinks.emplace_back(std::move(local_sink));
256415
256416 return local_sinks.back().get();
256417}
vector< LocalSortStatePtr > local_sinks
Local sort set.
Definition duckdb.cpp:60233
mutex lock
Finalize guard.
Definition duckdb.cpp:60231

◆ Finished()

void duckdb::WindowMergeSortTree::Finished ( )
virtual

Thread-safe post-sort cleanup.

Reimplemented in duckdb::WindowTokenTree.

256494 {
256495 global_sink.reset();
256496 local_sinks.clear();
256497 sorted.reset();
256498}
unique_ptr< ColumnDataCollection > sorted
The resulting sorted data.
Definition duckdb.cpp:60229
Here is the caller graph for this function:

◆ TryPrepareSortStage()

bool duckdb::WindowMergeSortTree::TryPrepareSortStage ( WindowMergeSortTreeLocalState & lstate)

Sort state machine.

256500 {
256501 lock_guard<mutex> stage_guard(lock);
256502
256503 switch (build_stage.load()) {
256504 case WindowMergeSortStage::INIT:
256505 total_tasks = local_sinks.size();
256506 tasks_assigned = 0;
256507 tasks_completed = 0;
256508 lstate.build_stage = build_stage = WindowMergeSortStage::COMBINE;
256509 lstate.build_task = tasks_assigned++;
256510 return true;
256511 case WindowMergeSortStage::COMBINE:
256512 // Process all the local sorts
256513 if (tasks_assigned < total_tasks) {
256514 lstate.build_stage = WindowMergeSortStage::COMBINE;
256515 lstate.build_task = tasks_assigned++;
256516 return true;
256517 } else if (tasks_completed < tasks_assigned) {
256518 return false;
256519 }
256520 // All combines are done, so move on to materialising the sorted data (1 task)
256521 total_tasks = 1;
256522 tasks_completed = 0;
256523 tasks_assigned = 0;
256524 lstate.build_stage = build_stage = WindowMergeSortStage::FINALIZE;
256525 lstate.build_task = tasks_assigned++;
256526 return true;
256527 case WindowMergeSortStage::FINALIZE:
256529 // Wait for the single task to finish
256530 return false;
256531 }
256532 // Move on to building the tree in parallel
256534 total_tasks = local_sinks.size();
256535 tasks_completed = 0;
256536 tasks_assigned = 0;
256537 lstate.build_stage = build_stage = WindowMergeSortStage::SORTED;
256538 lstate.build_task = tasks_assigned++;
256539 return true;
256540 case WindowMergeSortStage::SORTED:
256541 if (tasks_assigned < total_tasks) {
256542 lstate.build_stage = WindowMergeSortStage::SORTED;
256543 lstate.build_task = tasks_assigned++;
256544 return true;
256545 } else if (tasks_completed < tasks_assigned) {
256546 lstate.build_stage = WindowMergeSortStage::FINISHED;
256547 // Sleep while other tasks finish
256548 return false;
256549 }
256550 Finished();
256551 break;
256552 case WindowMergeSortStage::FINISHED:
256553 break;
256554 }
256555
256556 lstate.build_stage = build_stage = WindowMergeSortStage::FINISHED;
256557
256558 return true;
256559}
virtual idx_t MeasurePayloadBlocks()
Definition duckdb.cpp:256479
idx_t tasks_assigned
Tasks launched.
Definition duckdb.cpp:60239
virtual void Finished()
Thread-safe post-sort cleanup.
Definition duckdb.cpp:256494
idx_t total_tasks
Tasks launched.
Definition duckdb.cpp:60237
Here is the call graph for this function:

◆ Build()

void duckdb::WindowMergeSortTree::Build ( )

Build the MST in parallel from the sorted data.

256572 {
256573 if (mst32) {
256574 mst32->Build();
256575 } else {
256576 mst64->Build();
256577 }
256578}

◆ MeasurePayloadBlocks()

idx_t duckdb::WindowMergeSortTree::MeasurePayloadBlocks ( )
protectedvirtual

Find the starts of all the blocks Returns the total number of rows

Reimplemented in duckdb::WindowTokenTree.

256479 {
256480 const auto count = sorted->Count();
256481
256482 // Allocate the leaves.
256483 if (mst32) {
256484 mst32->Allocate(count);
256485 mst32->LowestLevel().resize(count);
256486 } else if (mst64) {
256487 mst64->Allocate(count);
256488 mst64->LowestLevel().resize(count);
256489 }
256490
256491 return count;
256492}
Here is the caller graph for this function:

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