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

PhysicalUngroupedAggregate is an aggregate operator that can only perform aggregates without any groups. More...

Inheritance diagram for duckdb::PhysicalUngroupedAggregate:
Collaboration diagram for duckdb::PhysicalUngroupedAggregate:

Public Member Functions

 PhysicalUngroupedAggregate (PhysicalPlan &physical_plan, vector< LogicalType > types, vector< unique_ptr< Expression > > expressions, idx_t estimated_cardinality, TupleDataValidityType distinct_validity)
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) 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
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
InsertionOrderPreservingMap< string > ParamsToString () const override
bool IsSink () const override
bool ParallelSink () const override
bool SinkOrderDependent () 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
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 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 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 > > aggregates
 The aggregates that have to be computed.
unique_ptr< DistinctAggregateData > distinct_data
unique_ptr< DistinctAggregateCollectionInfo > distinct_collection_info
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::UNGROUPED_AGGREGATE
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Private Member Functions

SinkFinalizeType FinalizeDistinct (Pipeline &pipeline, Event &event, ClientContext &context, GlobalSinkState &gstate) const
 Finalize the distinct aggregates.
void CombineDistinct (ExecutionContext &context, OperatorSinkCombineInput &input) const
 Combine the distinct aggregates.
void SinkDistinct (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const
 Sink the distinct aggregates.

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

PhysicalUngroupedAggregate is an aggregate operator that can only perform aggregates without any groups.

Constructor & Destructor Documentation

◆ PhysicalUngroupedAggregate()

duckdb::PhysicalUngroupedAggregate::PhysicalUngroupedAggregate ( PhysicalPlan & physical_plan,
vector< LogicalType > types,
vector< unique_ptr< Expression > > expressions,
idx_t estimated_cardinality,
TupleDataValidityType distinct_validity )
162606 : PhysicalOperator(physical_plan, PhysicalOperatorType::UNGROUPED_AGGREGATE, std::move(types),
162608 aggregates(std::move(expressions)) {
162609 distinct_collection_info = DistinctAggregateCollectionInfo::Create(aggregates);
162610 if (!distinct_collection_info) {
162611 return;
162612 }
162613 distinct_data = make_uniq<DistinctAggregateData>(*distinct_collection_info, distinct_validity);
162614}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
vector< unique_ptr< Expression > > aggregates
The aggregates that have to be computed.
Definition duckdb.cpp:162533

Member Function Documentation

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

163239 {
163240 auto &gstate = sink_state->Cast<UngroupedAggregateGlobalSinkState>();
163241 D_ASSERT(gstate.finished);
163242
163243 // initialize the result chunk with the aggregate values
163244 gstate.state.Finalize(chunk);
163245 VerifyNullHandling(chunk, gstate.state.state, aggregates);
163246
163247 return SourceResultType::FINISHED;
163248}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

162542 {
162543 return true;
162544 }

◆ Sink()

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

162918 {
162919 auto &sink = input.local_state.Cast<UngroupedAggregateLocalSinkState>();
162920
162921 // perform the aggregation inside the local state
162922 sink.execute_state.Reset();
162923
162924 if (distinct_data) {
162925 SinkDistinct(context, chunk, input);
162926 }
162927
162928 sink.execute_state.Sink(sink.state, chunk);
162929 return SinkResultType::NEED_MORE_INPUT;
162930}
void SinkDistinct(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const
Sink the distinct aggregates.
Definition duckdb.cpp:162874
Here is the call graph for this function:

◆ Combine()

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

162968 {
162969 auto &gstate = input.global_state.Cast<UngroupedAggregateGlobalSinkState>();
162970 auto &lstate = input.local_state.Cast<UngroupedAggregateLocalSinkState>();
162971 D_ASSERT(!gstate.finished);
162972
162973 // finalize: combine the local state into the global state
162974 // all aggregates are combinable: we might be doing a parallel aggregate
162975 // use the combine method to combine the partial aggregates
162976 OperatorSinkCombineInput distinct_input {gstate, lstate, input.interrupt_state};
162977 CombineDistinct(context, distinct_input);
162978
162979 gstate.state.Combine(lstate.state);
162980
162981 auto &client_profiler = QueryProfiler::Get(context.client);
162982 context.thread.profiler.Flush(*this);
162983 client_profiler.Flush(context.thread.profiler);
162984
162985 return SinkCombineResultType::FINISHED;
162986}
void CombineDistinct(ExecutionContext &context, OperatorSinkCombineInput &input) const
Combine the distinct aggregates.
Definition duckdb.cpp:162948
Here is the call graph for this function:

◆ Finalize()

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

163195 {
163196 auto &gstate = input.global_state.Cast<UngroupedAggregateGlobalSinkState>();
163197
163198 if (distinct_data) {
163199 return FinalizeDistinct(pipeline, event, context, input.global_state);
163200 }
163201
163202 D_ASSERT(!gstate.finished);
163203 gstate.finished = true;
163204 return SinkFinalizeType::READY;
163205}
SinkFinalizeType FinalizeDistinct(Pipeline &pipeline, Event &event, ClientContext &context, GlobalSinkState &gstate) const
Finalize the distinct aggregates.
Definition duckdb.cpp:163178
Here is the call graph for this function:

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

162868 {
162869 D_ASSERT(sink_state);
162870 auto &gstate = sink_state->Cast<UngroupedAggregateGlobalSinkState>();
162871 return make_uniq<UngroupedAggregateLocalSinkState>(*this, children[0].get().GetTypes(), gstate, context);
162872}
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::PhysicalUngroupedAggregate::GetGlobalSinkState ( ClientContext & context) const
overridevirtual

Reimplemented from duckdb::PhysicalOperator.

162864 {
162865 return make_uniq<UngroupedAggregateGlobalSinkState>(*this, context);
162866}

◆ ParamsToString()

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

Reimplemented from duckdb::PhysicalOperator.

163250 {
163251 InsertionOrderPreservingMap<string> result;
163252 string aggregate_info;
163253 for (idx_t i = 0; i < aggregates.size(); i++) {
163254 auto &aggregate = aggregates[i]->Cast<BoundAggregateExpression>();
163255 if (i > 0) {
163256 aggregate_info += "\n";
163257 }
163258 aggregate_info += aggregates[i]->GetName();
163259 if (aggregate.filter) {
163260 aggregate_info += " Filter: " + aggregate.filter->GetName();
163261 }
163262 }
163263 result["Aggregates"] = aggregate_info;
163264 return result;
163265}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

162558 {
162559 return true;
162560 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

162562 {
162563 return true;
162564 }

◆ SinkOrderDependent()

bool duckdb::PhysicalUngroupedAggregate::SinkOrderDependent ( ) const
overridevirtual

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.

162854 {
162855 for (auto &expr : aggregates) {
162856 auto &aggr = expr->Cast<BoundAggregateExpression>();
162857 if (aggr.function.GetOrderDependent() == AggregateOrderDependent::ORDER_DEPENDENT) {
162858 return true;
162859 }
162860 }
162861 return false;
162862}

◆ FinalizeDistinct()

SinkFinalizeType duckdb::PhysicalUngroupedAggregate::FinalizeDistinct ( Pipeline & pipeline,
Event & event,
ClientContext & context,
GlobalSinkState & gstate ) const
private

Finalize the distinct aggregates.

163179 {
163180 auto &gstate = gstate_p.Cast<UngroupedAggregateGlobalSinkState>();
163181 D_ASSERT(distinct_data);
163182 auto &distinct_state = *gstate.distinct_state;
163183
163184 for (idx_t table_idx = 0; table_idx < distinct_data->radix_tables.size(); table_idx++) {
163185 auto &radix_table_p = distinct_data->radix_tables[table_idx];
163186 auto &radix_state = *distinct_state.radix_states[table_idx];
163187 radix_table_p->Finalize(context, radix_state);
163188 }
163189 auto new_event = make_shared_ptr<UngroupedDistinctAggregateFinalizeEvent>(context, *this, gstate, pipeline);
163190 event.InsertEvent(std::move(new_event));
163191 return SinkFinalizeType::READY;
163192}
Here is the caller graph for this function:

◆ CombineDistinct()

void duckdb::PhysicalUngroupedAggregate::CombineDistinct ( ExecutionContext & context,
OperatorSinkCombineInput & input ) const
private

Combine the distinct aggregates.

162948 {
162949 auto &gstate = input.global_state.Cast<UngroupedAggregateGlobalSinkState>();
162950 auto &lstate = input.local_state.Cast<UngroupedAggregateLocalSinkState>();
162951
162952 if (!distinct_data) {
162953 return;
162954 }
162955 auto &distinct_state = gstate.distinct_state;
162956 auto table_count = distinct_data->radix_tables.size();
162957 for (idx_t table_idx = 0; table_idx < table_count; table_idx++) {
162958 D_ASSERT(distinct_data->radix_tables[table_idx]);
162959 auto &radix_table = *distinct_data->radix_tables[table_idx];
162960 auto &radix_global_sink = *distinct_state->radix_states[table_idx];
162961 auto &radix_local_sink = *lstate.radix_states[table_idx];
162962
162963 radix_table.Combine(context, radix_global_sink, radix_local_sink);
162964 }
162965}
Here is the caller graph for this function:

◆ SinkDistinct()

void duckdb::PhysicalUngroupedAggregate::SinkDistinct ( ExecutionContext & context,
DataChunk & chunk,
OperatorSinkInput & input ) const
private

Sink the distinct aggregates.

162875 {
162876 auto &sink = input.local_state.Cast<UngroupedAggregateLocalSinkState>();
162877 auto &global_sink = input.global_state.Cast<UngroupedAggregateGlobalSinkState>();
162878 D_ASSERT(distinct_data);
162879 auto &distinct_state = *global_sink.distinct_state;
162880 auto &distinct_info = *distinct_collection_info;
162881 auto &distinct_indices = distinct_info.Indices();
162882
162883 DataChunk empty_chunk;
162884
162885 auto &distinct_filter = distinct_info.Indices();
162886
162887 for (auto &idx : distinct_indices) {
162888 auto &aggregate = aggregates[idx]->Cast<BoundAggregateExpression>();
162889
162890 idx_t table_idx = distinct_info.table_map[idx];
162891 if (!distinct_data->radix_tables[table_idx]) {
162892 // This distinct aggregate shares its data with another
162893 continue;
162894 }
162895 D_ASSERT(distinct_data->radix_tables[table_idx]);
162896 auto &radix_table = *distinct_data->radix_tables[table_idx];
162897 auto &radix_global_sink = *distinct_state.radix_states[table_idx];
162898 auto &radix_local_sink = *sink.radix_states[table_idx];
162899 OperatorSinkInput sink_input {radix_global_sink, radix_local_sink, input.interrupt_state};
162900
162901 if (aggregate.filter) {
162902 // The hashtable can apply a filter, but only on the payload
162903 // And in our case, we need to filter the groups (the distinct aggr children)
162904
162905 // Apply the filter before inserting into the hashtable
162906 auto &filtered_data = sink.execute_state.filter_set.GetFilterData(idx);
162907 idx_t count = filtered_data.ApplyFilter(chunk);
162908 filtered_data.filtered_payload.SetCardinality(count);
162909
162910 radix_table.Sink(context, filtered_data.filtered_payload, sink_input, empty_chunk, distinct_filter);
162911 } else {
162912 radix_table.Sink(context, chunk, sink_input, empty_chunk, distinct_filter);
162913 }
162914 }
162915}
Here is the caller graph for this function:

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