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

PhysicalPartitionedAggregate is an aggregate operator that can only perform aggregates on data that is partitioned. More...

Inheritance diagram for duckdb::PhysicalPartitionedAggregate:
Collaboration diagram for duckdb::PhysicalPartitionedAggregate:

Public Member Functions

 PhysicalPartitionedAggregate (PhysicalPlan &physical_plan, ClientContext &context, vector< LogicalType > types, vector< unique_ptr< Expression > > expressions, vector< unique_ptr< Expression > > groups, vector< column_t > partitions, idx_t estimated_cardinality)
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const override
bool IsSource () 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
SinkNextBatchType NextBatch (ExecutionContext &context, OperatorSinkNextBatchInput &input) const override
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
InsertionOrderPreservingMap< string > ParamsToString () const override
OperatorPartitionInfo RequiredPartitionInfo () const override
bool IsSink () const override
bool ParallelSink () 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).
virtual unique_ptr< LocalSourceState > GetLocalSourceState (ExecutionContext &context, GlobalSourceState &gstate) 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 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 void PrepareFinalize (ClientContext &context, GlobalSinkState &sink_state) 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< column_t > partitions
 The partitions over which this is grouped.
vector< unique_ptr< Expression > > groups
 The groups over which the aggregate is partitioned - note that this is only.
vector< unique_ptr< Expression > > aggregates
 The aggregates that have to be computed.
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::PARTITIONED_AGGREGATE
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

PhysicalPartitionedAggregate is an aggregate operator that can only perform aggregates on data that is partitioned.

Constructor & Destructor Documentation

◆ PhysicalPartitionedAggregate()

duckdb::PhysicalPartitionedAggregate::PhysicalPartitionedAggregate ( PhysicalPlan & physical_plan,
ClientContext & context,
vector< LogicalType > types,
vector< unique_ptr< Expression > > expressions,
vector< unique_ptr< Expression > > groups,
vector< column_t > partitions,
idx_t estimated_cardinality )
161071 : PhysicalOperator(physical_plan, PhysicalOperatorType::PARTITIONED_AGGREGATE, std::move(types),
161073 partitions(std::move(partitions_p)), groups(std::move(groups_p)), aggregates(std::move(aggregates_p)) {
161074}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
vector< column_t > partitions
The partitions over which this is grouped.
Definition duckdb.cpp:160925
vector< unique_ptr< Expression > > groups
The groups over which the aggregate is partitioned - note that this is only.
Definition duckdb.cpp:160927
vector< unique_ptr< Expression > > aggregates
The aggregates that have to be computed.
Definition duckdb.cpp:160929

Member Function Documentation

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

161252 {
161253 auto &gstate = sink_state->Cast<PartitionedAggregateGlobalSinkState>();
161254 auto &gsource = input.global_state.Cast<PartitionedAggregateGlobalSourceState>();
161255 gstate.aggregate_result.Scan(gsource.scan_state, chunk);
161256 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
161257}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

161246 {
161247 auto &gstate = sink_state->Cast<PartitionedAggregateGlobalSinkState>();
161248 return make_uniq<PartitionedAggregateGlobalSourceState>(gstate);
161249}

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

160937 {
160938 return true;
160939 }

◆ Sink()

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

161153 {
161154 auto &gstate = input.global_state.Cast<PartitionedAggregateGlobalSinkState>();
161155 auto &lstate = input.local_state.Cast<PartitionedAggregateLocalSinkState>();
161156 if (!lstate.state) {
161157 // the local state is not yet initialized for this partition
161158 // initialize the partition
161159 child_list_t<Value> partition_values;
161160 for (idx_t partition_idx = 0; partition_idx < groups.size(); partition_idx++) {
161161 auto column_name = to_string(partition_idx);
161162 auto &partition = input.local_state.partition_info.partition_data[partition_idx];
161163 D_ASSERT(Value::NotDistinctFrom(partition.min_val, partition.max_val));
161164 partition_values.emplace_back(make_pair(std::move(column_name), partition.min_val));
161165 }
161166 lstate.current_partition = Value::STRUCT(std::move(partition_values));
161167
161168 // initialize the state
161169 auto &global_aggregate_state = gstate.GetOrCreatePartition(context.client, lstate.current_partition);
161170 lstate.state = make_uniq<LocalUngroupedAggregateState>(global_aggregate_state);
161171 }
161172
161173 // perform the aggregation
161174 lstate.execute_state.Sink(*lstate.state, chunk);
161175 return SinkResultType::NEED_MORE_INPUT;
161176}
static DUCKDB_API bool NotDistinctFrom(const Value &lvalue, const Value &rvalue)
Returns true if the values are not distinct from each other, following SQL semantics for NOT DISTINCT...
Definition duckdb.cpp:134034
static DUCKDB_API Value STRUCT(child_list_t< Value > values)
Create a struct value with given list of entries.
Definition duckdb.cpp:132434
std::string to_string(const T &value)
Definition duckdb.cpp:19425
int partition(const std::vector< _Tp > &_vec, std::vector< int > &labels, _EqPredicate predicate=_EqPredicate())
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ Combine()

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

161196 {
161197 auto &gstate = input.global_state.Cast<PartitionedAggregateGlobalSinkState>();
161198 auto &lstate = input.local_state.Cast<PartitionedAggregateLocalSinkState>();
161199 gstate.Combine(context.client, lstate);
161200 return SinkCombineResultType::FINISHED;
161201}

◆ Finalize()

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

161207 {
161208 auto &gstate = input.global_state.Cast<PartitionedAggregateGlobalSinkState>();
161209 ColumnDataAppendState append_state;
161210 gstate.aggregate_result.InitializeAppend(append_state);
161211 // finalize each of the partitions and append to a ColumnDataCollection
161212 DataChunk chunk;
161213 chunk.Initialize(context, types);
161214 for (auto &entry : gstate.aggregate_states) {
161215 chunk.Reset();
161216 // reference the partitions
161217 auto &partitions = StructValue::GetChildren(entry.first);
161218 for (idx_t partition_idx = 0; partition_idx < partitions.size(); partition_idx++) {
161219 chunk.data[partition_idx].Reference(partitions[partition_idx]);
161220 }
161221 // finalize the aggregates
161222 entry.second->Finalize(chunk, partitions.size());
161223
161224 // append to the CDC
161225 gstate.aggregate_result.Append(append_state, chunk);
161226 }
161227 return SinkFinalizeType::READY;
161228}
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
Here is the call graph for this function:

◆ NextBatch()

SinkNextBatchType duckdb::PhysicalPartitionedAggregate::NextBatch ( ExecutionContext & context,
OperatorSinkNextBatchInput & input ) const
overridevirtual

For sinks with RequiresBatchIndex set to true, when a new batch starts being processed this method is called This allows flushing of the current batch (e.g. to disk)

Reimplemented from duckdb::PhysicalOperator.

161182 {
161183 // flush the local state
161184 auto &gstate = input.global_state.Cast<PartitionedAggregateGlobalSinkState>();
161185 auto &lstate = input.local_state.Cast<PartitionedAggregateLocalSinkState>();
161186
161187 // finalize and reset the current state (if any)
161188 gstate.Combine(context.client, lstate);
161189 return SinkNextBatchType::READY;
161190}

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

161144 {
161145 D_ASSERT(sink_state);
161146 return make_uniq<PartitionedAggregateLocalSinkState>(*this, children[0].get().GetTypes(), context);
161147}
const vector< LogicalType > & GetTypes() const
Return a vector of the types that will be returned by this operator.
Definition duckdb.hpp:22174
ArenaLinkedList< reference< PhysicalOperator > > children
The child operators.
Definition duckdb.hpp:22148
__host__ cudaTextureObject_t get() const noexcept

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

161136 {
161137 return make_uniq<PartitionedAggregateGlobalSinkState>(*this, context);
161138}

◆ ParamsToString()

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

Reimplemented from duckdb::PhysicalOperator.

161262 {
161263 InsertionOrderPreservingMap<string> result;
161264 string groups_info;
161265 for (idx_t i = 0; i < groups.size(); i++) {
161266 if (i > 0) {
161267 groups_info += "\n";
161268 }
161269 groups_info += groups[i]->GetName();
161270 }
161271 result["Groups"] = groups_info;
161272 string aggregate_info;
161273 for (idx_t i = 0; i < aggregates.size(); i++) {
161274 auto &aggregate = aggregates[i]->Cast<BoundAggregateExpression>();
161275 if (i > 0) {
161276 aggregate_info += "\n";
161277 }
161278 aggregate_info += aggregates[i]->GetName();
161279 if (aggregate.filter) {
161280 aggregate_info += " Filter: " + aggregate.filter->GetName();
161281 }
161282 }
161283 result["Aggregates"] = aggregate_info;
161284 return result;
161285}

◆ RequiredPartitionInfo()

OperatorPartitionInfo duckdb::PhysicalPartitionedAggregate::RequiredPartitionInfo ( ) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

161076 {
161077 return OperatorPartitionInfo::PartitionColumns(partitions);
161078}

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

160955 {
160956 return true;
160957 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

160959 {
160960 return true;
160961 }

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