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::CachingPhysicalOperator Class Referenceabstract

#include <duckdb.hpp>

Inheritance diagram for duckdb::CachingPhysicalOperator:
Collaboration diagram for duckdb::CachingPhysicalOperator:

Public Member Functions

 CachingPhysicalOperator (PhysicalPlan &physical_plan, PhysicalOperatorType type, vector< LogicalType > types, idx_t estimated_cardinality)
OperatorResultType Execute (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const final
OperatorFinalizeResultType FinalExecute (ExecutionContext &context, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const final
bool RequiresFinalExecute () const final
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 InsertionOrderPreservingMap< string > ParamsToString () 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 OperatorFinalResultType OperatorFinalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorFinalizeInput &input) const
virtual bool ParallelOperator () const
virtual bool RequiresOperatorFinalize () const
virtual OrderPreservationType OperatorOrder () const
 The influence the operator has on order (insertion order means no influence).
virtual unique_ptr< LocalSourceState > GetLocalSourceState (ExecutionContext &context, GlobalSourceState &gstate) const
virtual unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const
SourceResultType GetData (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const
virtual OperatorPartitionData GetPartitionData (ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate, LocalSourceState &lstate, const OperatorPartitionInfo &partition_info) const
virtual bool IsSource () const
virtual bool ParallelSource () const
virtual bool SupportsPartitioning (const OperatorPartitionInfo &partition_info) const
virtual OrderPreservationType SourceOrder () const
 The type of order emitted by the operator (as a source).
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 SinkResultType Sink (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const
virtual SinkCombineResultType Combine (ExecutionContext &context, OperatorSinkCombineInput &input) const
virtual void PrepareFinalize (ClientContext &context, GlobalSinkState &sink_state) const
virtual SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const
virtual SinkNextBatchType NextBatch (ExecutionContext &context, OperatorSinkNextBatchInput &input) const
virtual unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const
virtual unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const
virtual bool IsSink () const
virtual bool ParallelSink () 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

bool caching_supported
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 idx_t CACHE_THRESHOLD = 64
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Protected Member Functions

virtual OperatorResultType ExecuteInternal (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const =0
 Child classes need to implement the ExecuteInternal method instead of the Execute.
Protected Member Functions inherited from duckdb::PhysicalOperator
virtual SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const

Private Member Functions

bool CanCacheType (const LogicalType &type)

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

Base class that caches output from child Operator class. Note that Operators inheriting from this class should also inherit their state class from the CachingOperatorState.

Constructor & Destructor Documentation

◆ CachingPhysicalOperator()

duckdb::CachingPhysicalOperator::CachingPhysicalOperator ( PhysicalPlan & physical_plan,
PhysicalOperatorType type,
vector< LogicalType > types,
idx_t estimated_cardinality )
201714 : PhysicalOperator(physical_plan, type, std::move(types_p), estimated_cardinality) {
201715 caching_supported = true;
201716 for (auto &col_type : types) {
201717 if (!CanCacheType(col_type)) {
201718 caching_supported = false;
201719 break;
201720 }
201721 }
201722}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
PhysicalOperatorType type
The physical operator type.
Definition duckdb.hpp:22150

Member Function Documentation

◆ Execute()

OperatorResultType duckdb::CachingPhysicalOperator::Execute ( ExecutionContext & context,
DataChunk & input,
DataChunk & chunk,
GlobalOperatorState & gstate,
OperatorState & state ) const
finalvirtual

This Execute will prevent small chunks from entering the pipeline, buffering them until a bigger chunk is created.

Reimplemented from duckdb::PhysicalOperator.

201816 {
201817 auto &state = state_p.Cast<CachingOperatorState>();
201818
201819 if (state.initialized && state.must_return_continuation_chunk) {
201820 chunk.Move(*state.cached_chunk);
201821 state.cached_chunk->Initialize(Allocator::Get(context.client), chunk.GetTypes());
201822 if (state.cached_result == OperatorResultType::BLOCKED && chunk.size() > 0) {
201823 // In case of BLOCKED, first the chunk + HAVE_MORE_OUTPUT, then blocking
201824 // This should currently be forbidden, so the assertion, but HAVE_MORE_OUTPUT is also a valid solution
201825 D_ASSERT(false);
201826 return OperatorResultType::HAVE_MORE_OUTPUT;
201827 }
201828 state.must_return_continuation_chunk = false;
201829 return state.cached_result;
201830 }
201831
201832 // Execute child operator
201833 auto child_result = ExecuteInternal(context, input, chunk, gstate, state);
201834
201835 if (!state.initialized) {
201836 state.initialized = true;
201837 state.must_return_continuation_chunk = false;
201838 if (caching_supported) {
201839 state.can_cache_chunk = PhysicalOperator::SelectOperatorCachingMode(context);
201840 } else {
201841 state.can_cache_chunk = OperatorCachingMode::NONE;
201842 }
201843 }
201844
201845 const auto execution_mode = SelectExecutionMode(chunk, child_result, state, context.client);
201846
201847 switch (execution_mode) {
201848 case CachingPhysicalOperatorExecuteMode::RETURN_CACHED_APPEND_CHUNK: {
201849 auto tmp = make_uniq<DataChunk>();
201850 tmp->Move(chunk);
201851 chunk.Move(*state.cached_chunk);
201852 state.cached_chunk->Initialize(Allocator::Get(context.client), chunk.GetTypes());
201853 state.cached_chunk->Append(*tmp);
201854 break;
201855 }
201856 case CachingPhysicalOperatorExecuteMode::RETURN_CACHED_PLUS_CHUNK:
201857 state.cached_chunk->Append(chunk);
201858 chunk.Move(*state.cached_chunk);
201859 state.cached_chunk->Initialize(Allocator::Get(context.client), chunk.GetTypes());
201860 break;
201861 case CachingPhysicalOperatorExecuteMode::RETURN_CACHED:
201862 D_ASSERT(chunk.size() == 0);
201863 chunk.Move(*state.cached_chunk);
201864 state.cached_chunk->Initialize(Allocator::Get(context.client), chunk.GetTypes());
201865 break;
201866 case CachingPhysicalOperatorExecuteMode::RETURN_CACHED_THEN_CHUNK_VIA_CONTINUATION: {
201867 // Swap chunk and *state.cached_chunk
201868 auto tmp = make_uniq<DataChunk>();
201869 tmp->Move(chunk);
201870 chunk.Move(*state.cached_chunk);
201871 state.cached_chunk->Initialize(Allocator::Get(context.client), chunk.GetTypes());
201872 state.cached_chunk->Move(*tmp);
201873
201874 // Now chunk holds what was in (*state.cached_chunk), and it's returned directly
201875 // While what was in chunk will be returned at next iteration via continuation
201876 state.must_return_continuation_chunk = true;
201877 state.cached_result = child_result;
201878 return OperatorResultType::HAVE_MORE_OUTPUT;
201879 }
201880 case CachingPhysicalOperatorExecuteMode::APPEND_CHUNK: {
201881 state.cached_chunk->Append(chunk);
201882 chunk.Reset();
201883 break;
201884 }
201885 case CachingPhysicalOperatorExecuteMode::RETURN_CHUNK:
201886 break;
201887 }
201888
201889 return child_result;
201890}
virtual OperatorResultType ExecuteInternal(ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const =0
Child classes need to implement the ExecuteInternal method instead of the Execute.
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API vector< LogicalType > GetTypes() const
Returns a list of types of the vectors of this data chunk.
Definition duckdb.cpp:116995
DUCKDB_API void Move(DataChunk &chunk)
Set the DataChunk to own the data of data chunk, destroying the other chunk in the process.
Definition duckdb.cpp:116888
static OperatorCachingMode SelectOperatorCachingMode(ExecutionContext &context)
Whether operator caching is allowed in the current execution context.
Definition duckdb.cpp:201596
Here is the call graph for this function:

◆ FinalExecute()

OperatorFinalizeResultType duckdb::CachingPhysicalOperator::FinalExecute ( ExecutionContext & context,
DataChunk & chunk,
GlobalOperatorState & gstate,
OperatorState & state ) const
finalvirtual

FinalExecute is used here to send out the remainder of the chunk (< STANDARD_VECTOR_SIZE) that we still had cached.

Reimplemented from duckdb::PhysicalOperator.

201894 {
201895 auto &state = state_p.Cast<CachingOperatorState>();
201896 if (state.cached_chunk) {
201897 chunk.Move(*state.cached_chunk);
201898 state.cached_chunk.reset();
201899 } else {
201900 chunk.SetCardinality(0);
201901 }
201902 return OperatorFinalizeResultType::FINISHED;
201903}
Here is the call graph for this function:

◆ RequiresFinalExecute()

bool duckdb::CachingPhysicalOperator::RequiresFinalExecute ( ) const
inlinefinalvirtual

Reimplemented from duckdb::PhysicalOperator.

22379 {
22380 return caching_supported;
22381 }

◆ ExecuteInternal()

virtual OperatorResultType duckdb::CachingPhysicalOperator::ExecuteInternal ( ExecutionContext & context,
DataChunk & input,
DataChunk & chunk,
GlobalOperatorState & gstate,
OperatorState & state ) const
protectedpure virtual

Child classes need to implement the ExecuteInternal method instead of the Execute.

Implemented in duckdb::PhysicalAsOfJoin, duckdb::PhysicalBlockwiseNLJoin, duckdb::PhysicalCrossProduct, duckdb::PhysicalFilter, duckdb::PhysicalHashJoin, duckdb::PhysicalIEJoin, duckdb::PhysicalNestedLoopJoin, and duckdb::PhysicalPiecewiseMergeJoin.

Here is the caller graph for this function:

◆ CanCacheType()

bool duckdb::CachingPhysicalOperator::CanCacheType ( const LogicalType & type)
private
201692 {
201693 switch (type.id()) {
201694 case LogicalTypeId::LIST:
201695 case LogicalTypeId::MAP:
201696 case LogicalTypeId::ARRAY:
201697 return false;
201698 case LogicalTypeId::STRUCT: {
201699 auto &entries = StructType::GetChildTypes(type);
201700 for (auto &entry : entries) {
201701 if (!CanCacheType(entry.second)) {
201702 return false;
201703 }
201704 }
201705 return true;
201706 }
201707 default:
201708 return true;
201709 }
201710}

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