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

Public Member Functions

 PhysicalTopN (PhysicalPlan &physical_plan, vector< LogicalType > types, vector< BoundOrderByNode > orders, idx_t limit, idx_t offset, shared_ptr< DynamicFilterData > dynamic_filter, idx_t estimated_cardinality)
unique_ptr< LocalSourceState > GetLocalSourceState (ExecutionContext &context, GlobalSourceState &gstate) const override
unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const override
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
OperatorPartitionData GetPartitionData (ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate, LocalSourceState &lstate, const OperatorPartitionInfo &partition_info) const override
bool IsSource () const override
bool ParallelSource () const override
bool SupportsPartitioning (const OperatorPartitionInfo &partition_info) const override
OrderPreservationType SourceOrder () const override
 The type of order emitted by the operator (as a source).
SinkResultType Sink (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const override
SinkCombineResultType Combine (ExecutionContext &context, OperatorSinkCombineInput &input) const override
SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const override
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
bool IsSink () const override
bool ParallelSink () const override
InsertionOrderPreservingMap< string > ParamsToString () const override
Public Member Functions inherited from duckdb::PhysicalOperator
 PhysicalOperator (PhysicalPlan &physical_plan, PhysicalOperatorType type, vector< LogicalType > types, idx_t estimated_cardinality)
 PhysicalOperator (const PhysicalOperator &other)=delete
 Deleted copy constructors.
PhysicalOperator & operator= (const PhysicalOperator &)=delete
virtual string GetName () const
virtual string ToString (ExplainFormat format=ExplainFormat::DEFAULT) const
void Print () const
virtual vector< const_reference< PhysicalOperator > > GetChildren () const
const vector< LogicalType > & GetTypes () const
 Return a vector of the types that will be returned by this operator.
virtual bool Equals (const PhysicalOperator &other) const
idx_t EstimatedThreadCount () const
 Functions to help decide how to set up pipeline dependencies.
bool CanSaturateThreads (ClientContext &context) const
virtual void Verify ()
virtual unique_ptr< OperatorState > GetOperatorState (ExecutionContext &context) const
virtual unique_ptr< GlobalOperatorState > GetGlobalOperatorState (ClientContext &context) const
virtual OperatorResultType Execute (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const
virtual OperatorFinalizeResultType FinalExecute (ExecutionContext &context, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const
virtual OperatorFinalResultType OperatorFinalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorFinalizeInput &input) const
virtual bool ParallelOperator () const
virtual bool RequiresFinalExecute () const
virtual bool RequiresOperatorFinalize () const
virtual OrderPreservationType OperatorOrder () const
 The influence the operator has on order (insertion order means no influence).
SourceResultType GetData (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const
virtual ProgressData GetProgress (ClientContext &context, GlobalSourceState &gstate) const
 Returns the current progress percentage, or a negative value if progress bars are not supported.
virtual ProgressData GetSinkProgress (ClientContext &context, GlobalSinkState &gstate, const ProgressData source_progress) const
 Returns the current progress percentage, or a negative value if progress bars are not supported.
virtual InsertionOrderPreservingMap< string > ExtraSourceParams (GlobalSourceState &gstate, LocalSourceState &lstate) const
virtual void PrepareFinalize (ClientContext &context, GlobalSinkState &sink_state) const
virtual SinkNextBatchType NextBatch (ExecutionContext &context, OperatorSinkNextBatchInput &input) const
virtual OperatorPartitionInfo RequiredPartitionInfo () const
virtual bool SinkOrderDependent () const
virtual vector< const_reference< PhysicalOperator > > GetSources () const
bool AllSourcesSupportBatchIndex () const
virtual void BuildPipelines (Pipeline &current, MetaPipeline &meta_pipeline)
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

vector< BoundOrderByNode > orders
idx_t limit
idx_t offset
shared_ptr< DynamicFilterData > dynamic_filter
 Dynamic table filter (if any).
Public Attributes inherited from duckdb::PhysicalOperator
ArenaLinkedList< reference< PhysicalOperator > > children
 The child operators.
PhysicalOperatorType type
 The physical operator type.
vector< LogicalType > types
 The return types.
idx_t estimated_cardinality
 The estimated cardinality.
unique_ptr< GlobalSinkState > sink_state
 The global sink state.
unique_ptr< GlobalOperatorState > op_state
 The global operator state.
mutex lock
 Lock for (re)setting any of the operator states.

Static Public Attributes

static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::TOP_N
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Additional Inherited Members

Static Public Member Functions inherited from duckdb::PhysicalOperator
static void SetEstimatedCardinality (InsertionOrderPreservingMap< string > &result, idx_t estimated_cardinality)
static idx_t GetMaxThreadMemory (ClientContext &context)
 The maximum amount of memory the operator should use per thread.
static OperatorCachingMode SelectOperatorCachingMode (ExecutionContext &context)
 Whether operator caching is allowed in the current execution context.

Detailed Description

Represents a physical ordering of the data. Note that this will not change the data but only add a selection vector.

Constructor & Destructor Documentation

◆ PhysicalTopN()

duckdb::PhysicalTopN::PhysicalTopN ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
vector< BoundOrderByNode > orders,
idx_t limit,
idx_t offset,
shared_ptr< DynamicFilterData > dynamic_filter,
idx_t estimated_cardinality )
190865 : PhysicalOperator(physical_plan, PhysicalOperatorType::TOP_N, std::move(types), estimated_cardinality),
190866 orders(std::move(orders)), limit(limit), offset(offset), dynamic_filter(std::move(dynamic_filter_p)) {
190867}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
shared_ptr< DynamicFilterData > dynamic_filter
Dynamic table filter (if any).
Definition duckdb.cpp:190800

◆ ~PhysicalTopN()

duckdb::PhysicalTopN::~PhysicalTopN ( )
override
190869 {
190870}

Member Function Documentation

◆ GetLocalSourceState()

unique_ptr< LocalSourceState > duckdb::PhysicalTopN::GetLocalSourceState ( ExecutionContext & context,
GlobalSourceState & gstate ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

191428 {
191429 return make_uniq<TopNLocalSourceState>();
191430}

◆ GetGlobalSourceState()

unique_ptr< GlobalSourceState > duckdb::PhysicalTopN::GetGlobalSourceState ( ClientContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

191423 {
191424 return make_uniq<TopNGlobalSourceState>(this->sink_state->Cast<TopNGlobalSinkState>());
191425}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ GetDataInternal()

SourceResultType duckdb::PhysicalTopN::GetDataInternal ( ExecutionContext & context,
DataChunk & chunk,
OperatorSourceInput & input ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

191433 {
191434 if (limit == 0) {
191435 return SourceResultType::FINISHED;
191436 }
191437 auto &sink = sink_state->Cast<TopNGlobalSinkState>();
191438 auto &gstate = input.global_state.Cast<TopNGlobalSourceState>();
191439 auto &lstate = input.local_state.Cast<TopNLocalSourceState>();
191440
191441 if (lstate.pos == lstate.end) {
191442 // Obtain new scan indices from the global state
191443 auto guard = gstate.Lock();
191444 lstate.pos = gstate.state.pos;
191445 gstate.state.pos += TopNGlobalSourceState::TUPLES_PER_BATCH;
191446 lstate.end = gstate.state.pos;
191447 lstate.batch_index = gstate.batch_index++;
191448 }
191449
191450 sink.heap.Scan(gstate.state, chunk, lstate.pos);
191451
191452 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
191453}

◆ GetPartitionData()

OperatorPartitionData duckdb::PhysicalTopN::GetPartitionData ( ExecutionContext & context,
DataChunk & chunk,
GlobalSourceState & gstate,
LocalSourceState & lstate,
const OperatorPartitionInfo & partition_info ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

191457 {
191458 if (partition_info.RequiresPartitionColumns()) {
191459 throw InternalException("PhysicalOrder::GetPartitionData: partition columns not supported");
191460 }
191461 auto &lstate = lstate_p.Cast<TopNLocalSourceState>();
191462 return OperatorPartitionData(lstate.batch_index);
191463}

◆ IsSource()

bool duckdb::PhysicalTopN::IsSource ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

190813 {
190814 return true;
190815 }

◆ ParallelSource()

bool duckdb::PhysicalTopN::ParallelSource ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

190817 {
190818 return true;
190819 }

◆ SupportsPartitioning()

bool duckdb::PhysicalTopN::SupportsPartitioning ( const OperatorPartitionInfo & partition_info) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

190821 {
190822 if (partition_info.RequiresPartitionColumns()) {
190823 return false;
190824 }
190825 return true;
190826 }

◆ SourceOrder()

OrderPreservationType duckdb::PhysicalTopN::SourceOrder ( ) const
inlineoverridevirtual

The type of order emitted by the operator (as a source).

Reimplemented from duckdb::PhysicalOperator.

190828 {
190829 return OrderPreservationType::FIXED_ORDER;
190830 }

◆ Sink()

SinkResultType duckdb::PhysicalTopN::Sink ( ExecutionContext & context,
DataChunk & chunk,
OperatorSinkInput & input ) const
overridevirtual

The sink method is called constantly with new input, as long as new input is available. Note that this method CAN be called in parallel, proper locking is needed when accessing dat a inside the GlobalSinkState.

Reimplemented from duckdb::PhysicalOperator.

191359 {
191360 // append to the local sink state
191361 auto &gstate = input.global_state.Cast<TopNGlobalSinkState>();
191362 auto &sink = input.local_state.Cast<TopNLocalSinkState>();
191363 sink.heap.Sink(chunk, &gstate.boundary_value);
191364 sink.heap.Reduce();
191365 return SinkResultType::NEED_MORE_INPUT;
191366}

◆ Combine()

SinkCombineResultType duckdb::PhysicalTopN::Combine ( ExecutionContext & context,
OperatorSinkCombineInput & input ) const
overridevirtual

The combine is called when a single thread has completed execution of its part of the pipeline, it is the final time that a specific LocalSinkState is accessible. This method can be called in parallel while other Sink() or Combine() calls are active on the same GlobalSinkState.

Reimplemented from duckdb::PhysicalOperator.

191371 {
191372 auto &gstate = input.global_state.Cast<TopNGlobalSinkState>();
191373 auto &lstate = input.local_state.Cast<TopNLocalSinkState>();
191374
191375 // scan the local top N and append it to the global heap
191376 lstate.heap.Finalize();
191377 lock_guard<mutex> guard(gstate.lock);
191378 gstate.heap.Combine(lstate.heap);
191379
191380 return SinkCombineResultType::FINISHED;
191381}

◆ Finalize()

SinkFinalizeType duckdb::PhysicalTopN::Finalize ( Pipeline & pipeline,
Event & event,
ClientContext & context,
OperatorSinkFinalizeInput & input ) const
overridevirtual

The finalize is called when ALL threads are finished execution. It is called only once per pipeline, and is entirely single threaded. If Finalize returns SinkResultType::Finished, the sink is marked as finished

Reimplemented from duckdb::PhysicalOperator.

191387 {
191388 auto &gstate = input.global_state.Cast<TopNGlobalSinkState>();
191389 // global finalize: compute the final top N
191390 gstate.heap.Finalize();
191391 return SinkFinalizeType::READY;
191392}

◆ GetLocalSinkState()

unique_ptr< LocalSinkState > duckdb::PhysicalTopN::GetLocalSinkState ( ExecutionContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

191345 {
191346 return make_uniq<TopNLocalSinkState>(context, types, orders, limit, offset);
191347}

◆ GetGlobalSinkState()

unique_ptr< GlobalSinkState > duckdb::PhysicalTopN::GetGlobalSinkState ( ClientContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

191349 {
191350 if (dynamic_filter) {
191351 dynamic_filter->Reset();
191352 }
191353 return make_uniq<TopNGlobalSinkState>(context, *this);
191354}

◆ IsSink()

bool duckdb::PhysicalTopN::IsSink ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

190840 {
190841 return true;
190842 }

◆ ParallelSink()

bool duckdb::PhysicalTopN::ParallelSink ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

190843 {
190844 return true;
190845 }

◆ ParamsToString()

InsertionOrderPreservingMap< string > duckdb::PhysicalTopN::ParamsToString ( ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

191465 {
191466 InsertionOrderPreservingMap<string> result;
191467 result["Top"] = to_string(limit);
191468 if (offset > 0) {
191469 result["Offset"] = to_string(offset);
191470 }
191471
191472 string orders_info;
191473 for (idx_t i = 0; i < orders.size(); i++) {
191474 if (i > 0) {
191475 orders_info += "\n";
191476 }
191477 orders_info += orders[i].expression->ToString() + " ";
191478 orders_info += orders[i].type == OrderType::DESCENDING ? "DESC" : "ASC";
191479 }
191480 result["Order By"] = orders_info;
191481 return result;
191482}
std::string to_string(const T &value)
Definition duckdb.cpp:19425
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

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