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

PhysicalAsOfJoin represents an as-of join between two tables. More...

Inheritance diagram for duckdb::PhysicalAsOfJoin:
Collaboration diagram for duckdb::PhysicalAsOfJoin:

Public Member Functions

 PhysicalAsOfJoin (PhysicalPlan &physical_plan, LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right)
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
bool IsSource () const override
bool ParallelSource () const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
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
bool IsSink () const override
bool ParallelSink () const override
void BuildPipelines (Pipeline &current, MetaPipeline &meta_pipeline) override
Public Member Functions inherited from duckdb::PhysicalComparisonJoin
 PhysicalComparisonJoin (PhysicalPlan &physical_plan, LogicalOperator &op, PhysicalOperatorType type, vector< JoinCondition > cond, JoinType join_type, idx_t estimated_cardinality)
InsertionOrderPreservingMap< string > ParamsToString () const override
Public Member Functions inherited from duckdb::PhysicalJoin
 PhysicalJoin (PhysicalPlan &physical_plan, LogicalOperator &op, PhysicalOperatorType type, JoinType join_type, idx_t estimated_cardinality)
bool EmptyResultIfRHSIsEmpty () const
void BuildPipelines (Pipeline &current, MetaPipeline &meta_pipeline) override
vector< const_reference< PhysicalOperator > > GetSources () const override
OrderPreservationType SourceOrder () const override
 The type of order emitted by the operator (as a source).
OrderPreservationType OperatorOrder () const override
 The influence the operator has on order (insertion order means no influence).
bool SinkOrderDependent () const override
Public Member Functions inherited from duckdb::CachingPhysicalOperator
 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 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
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 SupportsPartitioning (const OperatorPartitionInfo &partition_info) 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
bool AllSourcesSupportBatchIndex () const
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Public Attributes

vector< LogicalType > join_key_types
vector< column_t > null_sensitive
ExpressionType comparison_type
vector< unique_ptr< Expression > > lhs_partitions
vector< unique_ptr< Expression > > rhs_partitions
vector< BoundOrderByNode > lhs_orders
vector< BoundOrderByNode > rhs_orders
vector< column_t > right_projection_map
Public Attributes inherited from duckdb::PhysicalComparisonJoin
vector< JoinCondition > conditions
unique_ptr< JoinFilterPushdownInfo > filter_pushdown
 Scans where we should push generated filters into (if any).
Public Attributes inherited from duckdb::PhysicalJoin
JoinType join_type
Public Attributes inherited from duckdb::CachingPhysicalOperator
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 PhysicalOperatorType TYPE = PhysicalOperatorType::ASOF_JOIN
Static Public Attributes inherited from duckdb::PhysicalJoin
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID
Static Public Attributes inherited from duckdb::CachingPhysicalOperator
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

OperatorResultType ExecuteInternal (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const override
 Child classes need to implement the ExecuteInternal method instead of the Execute.

Additional Inherited Members

Static Public Member Functions inherited from duckdb::PhysicalComparisonJoin
static void ReorderConditions (vector< JoinCondition > &conditions)
 Re-order join conditions so that equality predicates are first, followed by other predicates.
static void ConstructEmptyJoinResult (JoinType type, bool has_null, DataChunk &input, DataChunk &result)
 Construct the join result of a join with an empty RHS.
static void ConstructFullOuterJoinResult (bool *found_match, ColumnDataCollection &input, DataChunk &result, ColumnDataScanState &scan_state)
 Construct the remainder of a Full Outer Join based on which tuples in the RHS found no match.
Static Public Member Functions inherited from duckdb::PhysicalJoin
static bool HasNullValues (DataChunk &chunk)
static void ConstructSemiJoinResult (DataChunk &left, DataChunk &result, bool found_match[])
static void ConstructAntiJoinResult (DataChunk &left, DataChunk &result, bool found_match[])
static void ConstructMarkJoinResult (DataChunk &join_keys, DataChunk &left, DataChunk &result, bool found_match[], bool has_null)
static void BuildJoinPipelines (Pipeline &current, MetaPipeline &meta_pipeline, PhysicalOperator &op, bool build_rhs=true)
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

PhysicalAsOfJoin represents an as-of join between two tables.

Constructor & Destructor Documentation

◆ PhysicalAsOfJoin()

duckdb::PhysicalAsOfJoin::PhysicalAsOfJoin ( PhysicalPlan & physical_plan,
LogicalComparisonJoin & op,
PhysicalOperator & left,
PhysicalOperator & right )
181679 : PhysicalComparisonJoin(physical_plan, op, PhysicalOperatorType::ASOF_JOIN, std::move(op.conditions), op.join_type,
181680 op.estimated_cardinality),
181681 comparison_type(ExpressionType::INVALID) {
181682 // Convert the conditions partitions and sorts
181683 D_ASSERT(!op.predicate.get());
181684 for (auto &cond : conditions) {
181685 D_ASSERT(cond.left->return_type == cond.right->return_type);
181686 join_key_types.push_back(cond.left->return_type);
181687
181688 auto left_cond = cond.left->Copy();
181689 auto right_cond = cond.right->Copy();
181690 switch (cond.comparison) {
181691 case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
181692 case ExpressionType::COMPARE_GREATERTHAN:
181693 null_sensitive.emplace_back(lhs_orders.size());
181694 lhs_orders.emplace_back(OrderType::ASCENDING, OrderByNullType::NULLS_LAST, std::move(left_cond));
181695 rhs_orders.emplace_back(OrderType::ASCENDING, OrderByNullType::NULLS_LAST, std::move(right_cond));
181696 comparison_type = cond.comparison;
181697 break;
181698 case ExpressionType::COMPARE_LESSTHANOREQUALTO:
181699 case ExpressionType::COMPARE_LESSTHAN:
181700 // Always put NULLS LAST so they can be ignored.
181701 null_sensitive.emplace_back(lhs_orders.size());
181702 lhs_orders.emplace_back(OrderType::DESCENDING, OrderByNullType::NULLS_LAST, std::move(left_cond));
181703 rhs_orders.emplace_back(OrderType::DESCENDING, OrderByNullType::NULLS_LAST, std::move(right_cond));
181704 comparison_type = cond.comparison;
181705 break;
181706 case ExpressionType::COMPARE_EQUAL:
181707 null_sensitive.emplace_back(lhs_orders.size());
181708 DUCKDB_EXPLICIT_FALLTHROUGH;
181709 case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
181710 lhs_partitions.emplace_back(std::move(left_cond));
181711 rhs_partitions.emplace_back(std::move(right_cond));
181712 break;
181713 default:
181714 throw NotImplementedException("Unsupported join condition for ASOF join");
181715 }
181716 }
181717 D_ASSERT(!lhs_orders.empty());
181718 D_ASSERT(!rhs_orders.empty());
181719
181720 children.push_back(left);
181721 children.push_back(right);
181722
181723 // Fill out the right projection map.
181724 right_projection_map = op.right_projection_map;
181725 if (right_projection_map.empty()) {
181726 const auto right_count = children[1].get().GetTypes().size();
181727 right_projection_map.reserve(right_count);
181728 for (column_t i = 0; i < right_count; ++i) {
181729 right_projection_map.emplace_back(i);
181730 }
181731 }
181732}
ArenaLinkedList< reference< PhysicalOperator > > children
The child operators.
Definition duckdb.hpp:22148
idx_t column_t
Type used for column identifiers.
Definition duckdb.hpp:259

Member Function Documentation

◆ ExecuteInternal()

OperatorResultType duckdb::PhysicalAsOfJoin::ExecuteInternal ( ExecutionContext & context,
DataChunk & input,
DataChunk & chunk,
GlobalOperatorState & gstate,
OperatorState & state ) const
overrideprotectedvirtual

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

Implements duckdb::CachingPhysicalOperator.

181836 {
181837 return OperatorResultType::FINISHED;
181838}

◆ GetLocalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

183041 {
183042 auto &gsource = gstate.Cast<AsOfGlobalSourceState>();
183043 return make_uniq<AsOfLocalSourceState>(context, gsource, *this);
183044}

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

182923 {
182924 return make_uniq<AsOfGlobalSourceState>(client, *this);
182925}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

183241 {
183242 auto &gsource = input.global_state.Cast<AsOfGlobalSourceState>();
183243 auto &lsource = input.local_state.Cast<AsOfLocalSourceState>();
183244
183245 // Any call to GetData must produce tuples, otherwise the pipeline executor thinks that we're done
183246 // Therefore, we loop until we've produced tuples, or until the operator is actually done
183247 while (gsource.HasUnfinishedTasks() && chunk.size() == 0) {
183248 if (!lsource.TaskFinished() || lsource.TryAssignTask()) {
183249 try {
183250 lsource.ExecuteTask(context, chunk, input);
183251 } catch (...) {
183252 gsource.stopped = true;
183253 throw;
183254 }
183255 } else {
183256 auto guard = gsource.Lock();
183257 if (!gsource.HasMoreTasks()) {
183258 gsource.UnblockTasks(guard);
183259 break;
183260 } else {
183261 // there are more tasks available, but we can't execute them yet
183262 // block the source
183263 return gsource.BlockSource(guard, input.interrupt_state);
183264 }
183265 }
183266 }
183267
183268 return chunk.size() > 0 ? SourceResultType::HAVE_MORE_OUTPUT : SourceResultType::FINISHED;
183269}

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

181634 {
181635 return true;
181636 }

◆ ParallelSource()

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

Reimplemented from duckdb::PhysicalOperator.

181637 {
181638 return true;
181639 }

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

181779 {
181780 return make_uniq<AsOfGlobalSinkState>(context, *this);
181781}

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

181783 {
181784 auto &gsink = sink_state->Cast<AsOfGlobalSinkState>();
181785 return make_uniq<AsOfLocalSinkState>(context, gsink);
181786}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ Sink()

SinkResultType duckdb::PhysicalAsOfJoin::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.

181788 {
181789 auto &gstate = sink.global_state.Cast<AsOfGlobalSinkState>();
181790 auto &lstate = sink.local_state.Cast<AsOfLocalSinkState>();
181791
181792 auto &sort_strategy = *gstate.sort_strategies[gstate.child];
181793 auto &gsink = *gstate.strategy_sinks[gstate.child];
181794 auto &lsink = *lstate.local_partition;
181795
181796 OperatorSinkInput hsink {gsink, lsink, sink.interrupt_state};
181797 return sort_strategy.Sink(context, chunk, hsink);
181798}

◆ Combine()

SinkCombineResultType duckdb::PhysicalAsOfJoin::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.

181800 {
181801 auto &gstate = combine.global_state.Cast<AsOfGlobalSinkState>();
181802 auto &lstate = combine.local_state.Cast<AsOfLocalSinkState>();
181803
181804 auto &sort_strategy = *gstate.sort_strategies[gstate.child];
181805 auto &gsink = *gstate.strategy_sinks[gstate.child];
181806 auto &lsink = *lstate.local_partition;
181807
181808 OperatorSinkCombineInput hcombine {gsink, lsink, combine.interrupt_state};
181809 return sort_strategy.Combine(context, hcombine);
181810}
cv::GKernelPackage combine(const cv::GKernelPackage &lhs, const cv::GKernelPackage &rhs)

◆ Finalize()

SinkFinalizeType duckdb::PhysicalAsOfJoin::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.

181816 {
181817 auto &gstate = finalize.global_state.Cast<AsOfGlobalSinkState>();
181818
181819 // The data is all in so we can synchronise the left partitioning.
181820 auto &sort_strategy = *gstate.sort_strategies[gstate.child];
181821 auto &hashed_sink = *gstate.strategy_sinks[gstate.child];
181822 OperatorSinkFinalizeInput hfinalize {hashed_sink, finalize.interrupt_state};
181823 if (gstate.child == 1) {
181824 auto &lhs_groups = *gstate.strategy_sinks[1 - gstate.child];
181825 auto &rhs_groups = hashed_sink;
181826 sort_strategy.Synchronize(rhs_groups, lhs_groups);
181827 }
181828
181829 // Switch sides
181830 gstate.child = 1 - gstate.child;
181831
181832 return sort_strategy.Finalize(client, hfinalize);
181833}

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

181650 {
181651 return true;
181652 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

181653 {
181654 return true;
181655 }

◆ BuildPipelines()

void duckdb::PhysicalAsOfJoin::BuildPipelines ( Pipeline & current,
MetaPipeline & meta_pipeline )
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

183311 {
183312 D_ASSERT(children.size() == 2);
183313 if (meta_pipeline.HasRecursiveCTE()) {
183314 throw NotImplementedException("AsOf joins are not supported in recursive CTEs yet");
183315 }
183316
183317 // becomes a source after both children fully sink their data
183318 meta_pipeline.GetState().SetPipelineSource(current, *this);
183319
183320 // Create one child meta pipeline that will hold the LHS and RHS pipelines
183321 auto &child_meta_pipeline = meta_pipeline.CreateChildMetaPipeline(current, *this);
183322
183323 // Build out RHS first because that is the order the join planner expects.
183324 auto rhs_pipeline = child_meta_pipeline.GetBasePipeline();
183325 children[1].get().BuildPipelines(*rhs_pipeline, child_meta_pipeline);
183326
183327 // Build out LHS
183328 auto &lhs_pipeline = child_meta_pipeline.CreatePipeline();
183329 children[0].get().BuildPipelines(lhs_pipeline, child_meta_pipeline);
183330
183331 // Despite having the same sink, LHS and everything created after it need their own (same) PipelineFinishEvent
183332 child_meta_pipeline.AddFinishEvent(lhs_pipeline);
183333}

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