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

The Pipeline class represents an execution pipeline starting at a. More...

#include <duckdb.hpp>

Inheritance diagram for duckdb::Pipeline:
Collaboration diagram for duckdb::Pipeline:

Public Member Functions

 Pipeline (Executor &execution_context)
ClientContext & GetClientContext ()
void AddDependency (shared_ptr< Pipeline > &pipeline)
vector< weak_ptr< Pipeline > > GetDependencies () const
void Ready ()
void Reset ()
void ResetSink ()
void ResetSource (bool force)
void ClearSource ()
void Schedule (shared_ptr< Event > &event)
void PrepareFinalize ()
string ToString () const
void Print () const
void PrintDependencies () const
bool GetProgress (ProgressData &progress_data)
 Returns query progress.
vector< reference< PhysicalOperator > > GetOperators ()
 Returns a list of all operators (including source and sink) involved in this pipeline.
vector< const_reference< PhysicalOperator > > GetOperators () const
const vector< reference< PhysicalOperator > > & GetIntermediateOperators () const
optional_ptr< PhysicalOperator > GetSink ()
optional_ptr< PhysicalOperator > GetSource ()
bool IsOrderDependent () const
 Returns whether any of the operators in the pipeline care about preserving order.
idx_t RegisterNewBatchIndex ()
 Registers a new batch index for a pipeline executor - returns the current minimum batch index.
idx_t UpdateBatchIndex (idx_t old_index, idx_t new_index)
 Updates the batch index of a pipeline (and returns the new minimum batch index).
Public Member Functions inherited from duckdb::enable_shared_from_this< Pipeline >
shared_ptr< Pipeline > shared_from_this ()

Public Attributes

Executor & executor

Private Member Functions

void ScheduleSequentialTask (shared_ptr< Event > &event)
bool LaunchScanTasks (shared_ptr< Event > &event, idx_t max_threads)
bool ScheduleParallel (shared_ptr< Event > &event)

Private Attributes

bool ready
 Whether or not the pipeline has been readied.
atomic< bool > initialized
 Whether or not the pipeline has been initialized.
optional_ptr< PhysicalOperator > source
 The source of this pipeline.
vector< reference< PhysicalOperator > > operators
 The chain of intermediate operators.
optional_ptr< PhysicalOperator > sink
 The sink (i.e. destination) for data; this is e.g. a hash table to-be-built.
unique_ptr< GlobalSourceState > source_state
 The global source state.
vector< weak_ptr< Pipeline > > parents
 The parent pipelines (i.e. pipelines that are dependent on this pipeline to finish).
vector< weak_ptr< Pipeline > > dependencies
 The dependencies of this pipeline.
idx_t base_batch_index = 0
 The base batch index of this pipeline.
mutex batch_lock
 Lock for accessing the set of batch indexes.
multiset< idx_t > batch_indexes

Friends

class Executor
class PipelineExecutor
class PipelineEvent
class PipelineFinishEvent
class PipelineBuildState
class MetaPipeline

Additional Inherited Members

Protected Member Functions inherited from duckdb::enable_shared_from_this< Pipeline >
enable_shared_from_this & operator= (enable_shared_from_this const &) noexcept

Detailed Description

The Pipeline class represents an execution pipeline starting at a.

Constructor & Destructor Documentation

◆ Pipeline()

duckdb::Pipeline::Pipeline ( Executor & execution_context)
explicit
329602 : executor(executor_p), ready(false), initialized(false), source(nullptr), sink(nullptr) {
329603}
optional_ptr< PhysicalOperator > sink
The sink (i.e. destination) for data; this is e.g. a hash table to-be-built.
Definition duckdb.hpp:26935
atomic< bool > initialized
Whether or not the pipeline has been initialized.
Definition duckdb.hpp:26929
optional_ptr< PhysicalOperator > source
The source of this pipeline.
Definition duckdb.hpp:26931
bool ready
Whether or not the pipeline has been readied.
Definition duckdb.hpp:26927

Member Function Documentation

◆ GetClientContext()

ClientContext & duckdb::Pipeline::GetClientContext ( )
329605 {
329606 return executor.context;
329607}

◆ AddDependency()

void duckdb::Pipeline::AddDependency ( shared_ptr< Pipeline > & pipeline)
329785 {
329786 D_ASSERT(pipeline);
329787 dependencies.push_back(weak_ptr<Pipeline>(pipeline));
329788 pipeline->parents.push_back(weak_ptr<Pipeline>(shared_from_this()));
329789}
vector< weak_ptr< Pipeline > > dependencies
The dependencies of this pipeline.
Definition duckdb.hpp:26943

◆ GetDependencies()

vector< weak_ptr< Pipeline > > duckdb::Pipeline::GetDependencies ( ) const
329791 {
329792 return dependencies;
329793}

◆ Ready()

void duckdb::Pipeline::Ready ( )
329777 {
329778 if (ready) {
329779 return;
329780 }
329781 ready = true;
329782 std::reverse(operators.begin(), operators.end());
329783}
vector< reference< PhysicalOperator > > operators
The chain of intermediate operators.
Definition duckdb.hpp:26933

◆ Reset()

void duckdb::Pipeline::Reset ( )
329753 {
329754 ResetSink();
329755 for (auto &op_ref : operators) {
329756 auto &op = op_ref.get();
329757 lock_guard<mutex> guard(op.lock);
329758 if (!op.op_state) {
329759 op.op_state = op.GetGlobalOperatorState(GetClientContext());
329760 }
329761 }
329762 ResetSource(false);
329763 // we no longer reset source here because this function is no longer guaranteed to be called by the main thread
329764 // source reset needs to be called by the main thread because resetting a source may call into clients like R
329765 initialized = true;
329766}

◆ ResetSink()

void duckdb::Pipeline::ResetSink ( )
329728 {
329729 if (sink) {
329730 if (!sink->IsSink()) {
329731 throw InternalException("Sink of pipeline does not have IsSink set");
329732 }
329733 lock_guard<mutex> guard(sink->lock);
329734 if (!sink->sink_state) {
329735 sink->sink_state = sink->GetGlobalSinkState(GetClientContext());
329736 }
329737 }
329738}

◆ ResetSource()

void duckdb::Pipeline::ResetSource ( bool force)
329768 {
329769 if (source && !source->IsSource()) {
329770 throw InternalException("Source of pipeline does not have IsSource set");
329771 }
329772 if (force || !source_state) {
329773 source_state = source->GetGlobalSourceState(GetClientContext());
329774 }
329775}
unique_ptr< GlobalSourceState > source_state
The global source state.
Definition duckdb.hpp:26938

◆ ClearSource()

void duckdb::Pipeline::ClearSource ( )
329840 {
329841 source_state.reset();
329842 batch_indexes.clear();
329843}
multiset< idx_t > batch_indexes
Definition duckdb.hpp:26953

◆ Schedule()

void duckdb::Pipeline::Schedule ( shared_ptr< Event > & event)
329702 {
329703 D_ASSERT(ready);
329704 D_ASSERT(sink);
329705 Reset();
329706 if (!ScheduleParallel(event)) {
329707 // could not parallelize this pipeline: push a sequential task instead
329708 ScheduleSequentialTask(event);
329709 }
329710}

◆ PrepareFinalize()

void duckdb::Pipeline::PrepareFinalize ( )
329740 {
329741 if (sink) {
329742 if (!sink->IsSink()) {
329743 throw InternalException("Sink of pipeline does not have IsSink set");
329744 }
329745 lock_guard<mutex> guard(sink->lock);
329746 if (!sink->sink_state) {
329747 throw InternalException("Sink of pipeline does not have sink state");
329748 }
329749 sink->PrepareFinalize(GetClientContext(), *sink->sink_state);
329750 }
329751}

◆ ToString()

string duckdb::Pipeline::ToString ( ) const
329795 {
329796 TextTreeRenderer renderer;
329797 return renderer.ToString(*this);
329798}

◆ Print()

void duckdb::Pipeline::Print ( ) const
329800 {
329801 Printer::Print(ToString());
329802}
static DUCKDB_API void Print(OutputStream stream, const string &str)
Print the object to the stream.
Definition duckdb.cpp:92556

◆ PrintDependencies()

void duckdb::Pipeline::PrintDependencies ( ) const
329804 {
329805 for (auto &dep : dependencies) {
329806 shared_ptr<Pipeline>(dep)->Print();
329807 }
329808}

◆ GetProgress()

bool duckdb::Pipeline::GetProgress ( ProgressData & progress_data)

Returns query progress.

329609 {
329610 D_ASSERT(source);
329611 idx_t source_cardinality = MinValue<idx_t>(source->estimated_cardinality, 1ULL << 48ULL);
329612 if (source_cardinality < 1) {
329613 source_cardinality = 1;
329614 }
329615 if (!initialized) {
329616 progress.done = 0;
329617 progress.total = double(source_cardinality);
329618 return true;
329619 }
329620 auto &client = executor.context;
329621
329622 progress = source->GetProgress(client, *source_state);
329623 progress.Normalize(double(source_cardinality));
329624 progress = sink->GetSinkProgress(client, *sink->sink_state, progress);
329625 return progress.IsValid();
329626}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ GetOperators() [1/2]

vector< reference< PhysicalOperator > > duckdb::Pipeline::GetOperators ( )

Returns a list of all operators (including source and sink) involved in this pipeline.

329810 {
329811 vector<reference<PhysicalOperator>> result;
329812 D_ASSERT(source);
329813 result.push_back(*source);
329814 for (auto &op : operators) {
329815 result.push_back(op.get());
329816 }
329817 if (sink) {
329818 result.push_back(*sink);
329819 }
329820 return result;
329821}

◆ GetOperators() [2/2]

vector< const_reference< PhysicalOperator > > duckdb::Pipeline::GetOperators ( ) const
329823 {
329824 vector<const_reference<PhysicalOperator>> result;
329825 D_ASSERT(source);
329826 result.push_back(*source);
329827 for (auto &op : operators) {
329828 result.push_back(op.get());
329829 }
329830 if (sink) {
329831 result.push_back(*sink);
329832 }
329833 return result;
329834}

◆ GetIntermediateOperators()

const vector< reference< PhysicalOperator > > & duckdb::Pipeline::GetIntermediateOperators ( ) const
329836 {
329837 return operators;
329838}

◆ GetSink()

optional_ptr< PhysicalOperator > duckdb::Pipeline::GetSink ( )
inline
26908 {
26909 return sink;
26910 }

◆ GetSource()

optional_ptr< PhysicalOperator > duckdb::Pipeline::GetSource ( )
inline
26912 {
26913 return source;
26914 }

◆ IsOrderDependent()

bool duckdb::Pipeline::IsOrderDependent ( ) const

Returns whether any of the operators in the pipeline care about preserving order.

329674 {
329675 if (source) {
329676 auto source_order = source->SourceOrder();
329677 if (source_order == OrderPreservationType::FIXED_ORDER) {
329678 return true;
329679 }
329680 if (source_order == OrderPreservationType::NO_ORDER) {
329681 return false;
329682 }
329683 }
329684 for (auto &op_ref : operators) {
329685 auto &op = op_ref.get();
329686 if (op.OperatorOrder() == OrderPreservationType::NO_ORDER) {
329687 return false;
329688 }
329689 if (op.OperatorOrder() == OrderPreservationType::FIXED_ORDER) {
329690 return true;
329691 }
329692 }
329693 if (!Settings::Get<PreserveInsertionOrderSetting>(executor.context)) {
329694 return false;
329695 }
329696 if (sink && sink->SinkOrderDependent()) {
329697 return true;
329698 }
329699 return false;
329700}

◆ RegisterNewBatchIndex()

idx_t duckdb::Pipeline::RegisterNewBatchIndex ( )

Registers a new batch index for a pipeline executor - returns the current minimum batch index.

329845 {
329846 lock_guard<mutex> l(batch_lock);
329847 idx_t minimum = batch_indexes.empty() ? base_batch_index : *batch_indexes.begin();
329848 batch_indexes.insert(minimum);
329849 return minimum;
329850}
mutex batch_lock
Lock for accessing the set of batch indexes.
Definition duckdb.hpp:26948
idx_t base_batch_index
The base batch index of this pipeline.
Definition duckdb.hpp:26946

◆ UpdateBatchIndex()

idx_t duckdb::Pipeline::UpdateBatchIndex ( idx_t old_index,
idx_t new_index )

Updates the batch index of a pipeline (and returns the new minimum batch index).

329852 {
329853 lock_guard<mutex> l(batch_lock);
329854 if (new_index < *batch_indexes.begin()) {
329855 throw InternalException("Processing batch index %llu, but previous min batch index was %llu", new_index,
329856 *batch_indexes.begin());
329857 }
329858 auto entry = batch_indexes.find(old_index);
329859 if (entry == batch_indexes.end()) {
329860 throw InternalException("Batch index %llu was not found in set of active batch indexes", old_index);
329861 }
329862 batch_indexes.erase(entry);
329863 batch_indexes.insert(new_index);
329864 return *batch_indexes.begin();
329865}

◆ ScheduleSequentialTask()

void duckdb::Pipeline::ScheduleSequentialTask ( shared_ptr< Event > & event)
private
329628 {
329629 vector<shared_ptr<Task>> tasks;
329630 tasks.push_back(make_uniq<PipelineTask>(*this, event));
329631 event->SetTasks(std::move(tasks));
329632}

◆ LaunchScanTasks()

bool duckdb::Pipeline::LaunchScanTasks ( shared_ptr< Event > & event,
idx_t max_threads )
private
329712 {
329713 // split the scan up into parts and schedule the parts
329714 if (max_threads <= 1) {
329715 // too small to parallelize
329716 return false;
329717 }
329718
329719 // launch a task for every thread
329720 vector<shared_ptr<Task>> tasks;
329721 for (idx_t i = 0; i < max_threads; i++) {
329722 tasks.push_back(make_uniq<PipelineTask>(*this, event));
329723 }
329724 event->SetTasks(std::move(tasks));
329725 return true;
329726}

◆ ScheduleParallel()

bool duckdb::Pipeline::ScheduleParallel ( shared_ptr< Event > & event)
private
329634 {
329635 // check if the sink, source and all intermediate operators support parallelism
329636 if (!sink->ParallelSink()) {
329637 return false;
329638 }
329639 if (!source->ParallelSource()) {
329640 return false;
329641 }
329642 auto max_threads = source_state->MaxThreads();
329643
329644 for (auto &op_ref : operators) {
329645 auto &op = op_ref.get();
329646 if (!op.ParallelOperator()) {
329647 return false;
329648 }
329649 max_threads = MinValue<idx_t>(max_threads, op.op_state->MaxThreads(max_threads));
329650 }
329651
329652 auto partition_info = sink->RequiredPartitionInfo();
329653 if (partition_info.batch_index) {
329654 if (!source->SupportsPartitioning(OperatorPartitionInfo::BatchIndex())) {
329655 throw InternalException(
329656 "Attempting to schedule a pipeline where the sink requires batch index but source does not support it");
329657 }
329658 }
329659
329660 auto &scheduler = TaskScheduler::GetScheduler(executor.context);
329661 auto active_threads = NumericCast<idx_t>(scheduler.NumberOfThreads());
329662 if (max_threads > active_threads) {
329663 max_threads = active_threads;
329664 }
329665 if (sink && sink->sink_state) {
329666 max_threads = sink->sink_state->MaxThreads(max_threads);
329667 }
329668 if (max_threads > active_threads) {
329669 max_threads = active_threads;
329670 }
329671 return LaunchScanTasks(event, max_threads);
329672}

Member Data Documentation

◆ batch_indexes

multiset<idx_t> duckdb::Pipeline::batch_indexes
private

The set of batch indexes that are currently being processed Despite batch indexes being unique - this is a multiset The reason is that when we start a new pipeline we insert the current minimum batch index as a placeholder Which leads to duplicate entries in the set of active batch indexes


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