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

Public Member Functions

 PhysicalWindow (PhysicalPlan &physical_plan, vector< LogicalType > types, vector< unique_ptr< Expression > > select_list, idx_t estimated_cardinality, PhysicalOperatorType type=PhysicalOperatorType::WINDOW)
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).
ProgressData GetProgress (ClientContext &context, GlobalSourceState &gstate_p) const override
 Returns the current progress percentage, or a negative value if progress bars are not supported.
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
ProgressData GetSinkProgress (ClientContext &context, GlobalSinkState &gstate, const ProgressData source_progress) const override
 Returns the current progress percentage, or a negative value if progress bars are not supported.
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
bool IsSink () const override
bool ParallelSink () const override
bool SinkOrderDependent () const override
idx_t MaxThreads (ClientContext &context)
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 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 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< unique_ptr< Expression > > select_list
 The projection list of the WINDOW statement (may contain aggregates).
idx_t order_idx
 The window expression with the order clause.
bool is_order_dependent
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::WINDOW
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

PhysicalWindow implements window functions It assumes that all functions have a common partitioning and ordering

Constructor & Destructor Documentation

◆ PhysicalWindow()

duckdb::PhysicalWindow::PhysicalWindow ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
vector< unique_ptr< Expression > > select_list,
idx_t estimated_cardinality,
PhysicalOperatorType type = PhysicalOperatorType::WINDOW )
164654 : PhysicalOperator(physical_plan, type, std::move(types), estimated_cardinality),
164655 select_list(std::move(select_list_p)), order_idx(0), is_order_dependent(false) {
164656 idx_t max_orders = 0;
164657 for (idx_t i = 0; i < select_list.size(); ++i) {
164658 auto &expr = select_list[i];
164659 D_ASSERT(expr->GetExpressionClass() == ExpressionClass::BOUND_WINDOW);
164660 auto &bound_window = expr->Cast<BoundWindowExpression>();
164661 if (bound_window.partitions.empty() && bound_window.orders.empty()) {
164662 is_order_dependent = true;
164663 }
164664
164665 if (bound_window.orders.size() > max_orders) {
164666 order_idx = i;
164667 max_orders = bound_window.orders.size();
164668 }
164669 }
164670}
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
idx_t order_idx
The window expression with the order clause.
Definition duckdb.cpp:163296
bool is_order_dependent
Definition duckdb.cpp:163299
vector< unique_ptr< Expression > > select_list
The projection list of the WINDOW statement (may contain aggregates).
Definition duckdb.cpp:163294
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ GetLocalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

165457 {
165458 auto &gsource = gsource_p.Cast<WindowGlobalSourceState>();
165459 return make_uniq<WindowLocalSourceState>(gsource);
165460}

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

165462 {
165463 auto &gsink = sink_state->Cast<WindowGlobalSinkState>();
165464 return make_uniq<WindowGlobalSourceState>(client, gsink);
165465}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

165522 {
165523 auto &gsource = source.global_state.Cast<WindowGlobalSourceState>();
165524 auto &lsource = source.local_state.Cast<WindowLocalSourceState>();
165525
165526 while (gsource.HasUnfinishedTasks() && chunk.size() == 0) {
165527 if (!lsource.TaskFinished() || lsource.TryAssignTask()) {
165528 try {
165529 lsource.ExecuteTask(context, chunk, source.interrupt_state);
165530 } catch (...) {
165531 gsource.stopped = true;
165532 throw;
165533 }
165534 } else {
165535 auto guard = gsource.Lock();
165536 if (!gsource.HasMoreTasks()) {
165537 // no more tasks - exit
165538 gsource.UnblockTasks(guard);
165539 break;
165540 } else {
165541 // there are more tasks available, but we can't execute them yet
165542 // block the source
165543 return gsource.BlockSource(guard, source.interrupt_state);
165544 }
165545 }
165546 }
165547
165548 if (chunk.size() == 0) {
165549 return SourceResultType::FINISHED;
165550 }
165551 return SourceResultType::HAVE_MORE_OUTPUT;
165552}

◆ GetPartitionData()

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

Reimplemented from duckdb::PhysicalOperator.

165513 {
165514 if (partition_info.RequiresPartitionColumns()) {
165515 throw InternalException("PhysicalWindow::GetPartitionData: partition columns not supported");
165516 }
165517 auto &lstate = lstate_p.Cast<WindowLocalSourceState>();
165518 return OperatorPartitionData(lstate.batch_index);
165519}

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

163312 {
163313 return true;
163314 }

◆ ParallelSource()

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

Reimplemented from duckdb::PhysicalOperator.

163315 {
163316 return true;
163317 }

◆ SupportsPartitioning()

bool duckdb::PhysicalWindow::SupportsPartitioning ( const OperatorPartitionInfo & partition_info) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

165467 {
165468 if (partition_info.RequiresPartitionColumns()) {
165469 return false;
165470 }
165471 // We can only preserve order for single partitioning
165472 // or work stealing causes out of order batch numbers
165473 auto &wexpr = select_list[order_idx]->Cast<BoundWindowExpression>();
165474 return wexpr.partitions.empty(); // NOLINT
165475}

◆ SourceOrder()

OrderPreservationType duckdb::PhysicalWindow::SourceOrder ( ) const
overridevirtual

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

Reimplemented from duckdb::PhysicalOperator.

165477 {
165478 auto &wexpr = select_list[order_idx]->Cast<BoundWindowExpression>();
165479 if (!wexpr.partitions.empty()) {
165480 // if we have partitions the window order is not defined
165481 return OrderPreservationType::NO_ORDER;
165482 }
165483 // without partitions we can maintain order
165484 if (wexpr.orders.empty()) {
165485 // if we have no orders we maintain insertion order
165486 return OrderPreservationType::INSERTION_ORDER;
165487 }
165488 // otherwise we can maintain the fixed order
165489 return OrderPreservationType::FIXED_ORDER;
165490}

◆ GetProgress()

ProgressData duckdb::PhysicalWindow::GetProgress ( ClientContext & context,
GlobalSourceState & gstate ) const
overridevirtual

Returns the current progress percentage, or a negative value if progress bars are not supported.

Reimplemented from duckdb::PhysicalOperator.

165492 {
165493 auto &gsource = gsource_p.Cast<WindowGlobalSourceState>();
165494 auto &gsink = gsource.gsink;
165495 const auto count = gsink.count.load();
165496 const auto completed = gsource.completed.load();
165497
165498 ProgressData res;
165499 if (count) {
165500 res.done = double(completed);
165501 res.total = double(gsource.total_tasks);
165502 // Convert to tuples.
165503 res.Normalize(double(count));
165504 } else {
165505 res.SetInvalid();
165506 }
165507
165508 return res;
165509}

◆ Sink()

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

164727 {
164728 auto &gstate = sink.global_state.Cast<WindowGlobalSinkState>();
164729 auto &lstate = sink.local_state.Cast<WindowLocalSinkState>();
164730 gstate.count += chunk.size();
164731
164732 OperatorSinkInput hsink {*gstate.strategy_sink, *lstate.local_group, sink.interrupt_state};
164733 return gstate.sort_strategy->Sink(context, chunk, hsink);
164734}

◆ Combine()

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

164736 {
164737 auto &gstate = combine.global_state.Cast<WindowGlobalSinkState>();
164738 auto &lstate = combine.local_state.Cast<WindowLocalSinkState>();
164739
164740 OperatorSinkCombineInput hcombine {*gstate.strategy_sink, *lstate.local_group, combine.interrupt_state};
164741 return gstate.sort_strategy->Combine(context, hcombine);
164742}
cv::GKernelPackage combine(const cv::GKernelPackage &lhs, const cv::GKernelPackage &rhs)

◆ Finalize()

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

164754 {
164755 auto &gsink = input.global_state.Cast<WindowGlobalSinkState>();
164756 auto &sort_strategy = *gsink.sort_strategy;
164757 auto &strategy_sink = *gsink.strategy_sink;
164758
164759 OperatorSinkFinalizeInput hfinalize {strategy_sink, input.interrupt_state};
164760 return sort_strategy.Finalize(client, hfinalize);
164761}

◆ GetSinkProgress()

ProgressData duckdb::PhysicalWindow::GetSinkProgress ( ClientContext & context,
GlobalSinkState & gstate,
const ProgressData source_progress ) const
overridevirtual

Returns the current progress percentage, or a negative value if progress bars are not supported.

Reimplemented from duckdb::PhysicalOperator.

164764 {
164765 auto &gsink = gstate.Cast<WindowGlobalSinkState>();
164766 return gsink.sort_strategy->GetSinkProgress(context, *gsink.strategy_sink, source_progress);
164767}

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

164744 {
164745 auto &gstate = sink_state->Cast<WindowGlobalSinkState>();
164746 return make_uniq<WindowLocalSinkState>(context, gstate);
164747}

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

164749 {
164750 return make_uniq<WindowGlobalSinkState>(*this, client);
164751}

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

163336 {
163337 return true;
163338 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

163340 {
163341 return !is_order_dependent;
163342 }

◆ SinkOrderDependent()

bool duckdb::PhysicalWindow::SinkOrderDependent ( ) const
inlineoverridevirtual

Whether or not the sink operator depends on the order of the input chunks If this is set to true, we cannot do things like caching intermediate vectors

Reimplemented from duckdb::PhysicalOperator.

163344 {
163345 return is_order_dependent;
163346 }

◆ ParamsToString()

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

Reimplemented from duckdb::PhysicalOperator.

165554 {
165555 InsertionOrderPreservingMap<string> result;
165556 string projections;
165557 for (idx_t i = 0; i < select_list.size(); i++) {
165558 if (i > 0) {
165559 projections += "\n";
165560 }
165561 projections += select_list[i]->GetName();
165562 }
165563 result["Projections"] = projections;
165564 return result;
165565}

Member Data Documentation

◆ is_order_dependent

bool duckdb::PhysicalWindow::is_order_dependent

Whether or not the window is order dependent (only true if ANY window function contains neither an order nor a partition clause)


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