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

PhysicalPivot implements the physical PIVOT operation. More...

Inheritance diagram for duckdb::PhysicalPivot:
Collaboration diagram for duckdb::PhysicalPivot:

Public Member Functions

 PhysicalPivot (PhysicalPlan &physical_plan, vector< LogicalType > types, PhysicalOperator &child, BoundPivotInfo bound_pivot)
OperatorResultType Execute (ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const override
bool ParallelOperator () 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 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 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 RequiresFinalExecute () 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

BoundPivotInfo bound_pivot
string_map_t< idx_t > pivot_map
 The map for pivot value -> column index.
vector< Value > empty_aggregates
 The empty aggregate values.
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.

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.
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID
Protected Member Functions inherited from duckdb::PhysicalOperator
virtual SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const

Detailed Description

PhysicalPivot implements the physical PIVOT operation.

Constructor & Destructor Documentation

◆ PhysicalPivot()

duckdb::PhysicalPivot::PhysicalPivot ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
PhysicalOperator & child,
BoundPivotInfo bound_pivot )
197438 : PhysicalOperator(physical_plan, PhysicalOperatorType::PIVOT, std::move(types_p), child.estimated_cardinality),
197439 bound_pivot(std::move(bound_pivot_p)) {
197440 children.push_back(child);
197441 for (idx_t p = 0; p < bound_pivot.pivot_values.size(); p++) {
197442 auto entry = pivot_map.find(bound_pivot.pivot_values[p]);
197443 if (entry != pivot_map.end()) {
197444 continue;
197445 }
197446 pivot_map[bound_pivot.pivot_values[p]] = bound_pivot.group_count + p;
197447 }
197448 // extract the empty aggregate expressions
197449 for (auto &aggr_expr : bound_pivot.aggregates) {
197450 auto &aggr = aggr_expr->Cast<BoundAggregateExpression>();
197451 // for each aggregate, initialize an empty aggregate state and finalize it immediately
197452 auto state = make_unsafe_uniq_array<data_t>(aggr.function.GetStateSizeCallback()(aggr.function));
197453 aggr.function.GetStateInitCallback()(aggr.function, state.get());
197454 Vector state_vector(Value::POINTER(CastPointerToValue(state.get())));
197455 Vector result_vector(aggr_expr->return_type);
197456 AggregateInputData aggr_input_data(aggr.bind_info.get(), physical_plan.ArenaRef());
197457 aggr.function.GetStateFinalizeCallback()(state_vector, aggr_input_data, result_vector, 1, 0);
197458 empty_aggregates.push_back(result_vector.GetValue(0));
197459 }
197460}
ArenaLinkedList< reference< PhysicalOperator > > children
The child operators.
Definition duckdb.hpp:22148
vector< Value > empty_aggregates
The empty aggregate values.
Definition duckdb.cpp:197417
string_map_t< idx_t > pivot_map
The map for pivot value -> column index.
Definition duckdb.cpp:197415
static DUCKDB_API Value POINTER(uintptr_t value)
Create a pointer Value from a specified value.
Definition duckdb.cpp:132331
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ Execute()

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

Reimplemented from duckdb::PhysicalOperator.

197463 {
197464 // copy the groups as-is
197465 input.Flatten();
197466 for (idx_t i = 0; i < bound_pivot.group_count; i++) {
197467 chunk.data[i].Reference(input.data[i]);
197468 }
197469 auto pivot_column_lists = FlatVector::GetData<list_entry_t>(input.data.back());
197470 auto &pivot_column_values = ListVector::GetEntry(input.data.back());
197471 auto pivot_columns = FlatVector::GetData<string_t>(pivot_column_values);
197472
197473 // initialize all aggregate columns with the empty aggregate value
197474 // if there are multiple aggregates the columns are in order of [AGGR1][AGGR2][AGGR1][AGGR2]
197475 // so we need to alternate the empty_aggregate that we use
197476 idx_t aggregate = 0;
197477 for (idx_t c = bound_pivot.group_count; c < chunk.ColumnCount(); c++) {
197478 chunk.data[c].Reference(empty_aggregates[aggregate]);
197479 chunk.data[c].Flatten(input.size());
197480 aggregate++;
197481 if (aggregate >= empty_aggregates.size()) {
197482 aggregate = 0;
197483 }
197484 }
197485
197486 // move the pivots to the given columns
197487 for (idx_t r = 0; r < input.size(); r++) {
197488 auto list = pivot_column_lists[r];
197489 for (idx_t l = 0; l < list.length; l++) {
197490 // figure out the column value number of this list
197491 auto &column_name = pivot_columns[list.offset + l];
197492 auto entry = pivot_map.find(column_name);
197493 if (entry == pivot_map.end()) {
197494 // column entry not found in map - that means this element is explicitly excluded from the pivot list
197495 continue;
197496 }
197497 auto column_idx = entry->second;
197498 for (idx_t aggr = 0; aggr < empty_aggregates.size(); aggr++) {
197499 auto pivot_value_lists = FlatVector::GetData<list_entry_t>(input.data[bound_pivot.group_count + aggr]);
197500 auto &pivot_value_child = ListVector::GetEntry(input.data[bound_pivot.group_count + aggr]);
197501 if (list.length != pivot_value_lists[r].length) {
197502 throw InternalException("Pivot - unaligned lists between values and columns!?");
197503 }
197504 chunk.data[column_idx + aggr].SetValue(r, pivot_value_child.GetValue(pivot_value_lists[r].offset + l));
197505 }
197506 }
197507 }
197508 chunk.SetCardinality(input.size());
197509 return OperatorResultType::NEED_MORE_INPUT;
197510}
DUCKDB_API void Flatten()
Turn all the vectors from the chunk into flat vectors.
Definition duckdb.cpp:116989
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of a list.
Definition duckdb.cpp:138203

◆ ParallelOperator()

bool duckdb::PhysicalPivot::ParallelOperator ( ) const
inlineoverridevirtual

Reimplemented from duckdb::PhysicalOperator.

197423 {
197424 return true;
197425 }

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