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

Public Member Functions

 PhysicalHashAggregate (PhysicalPlan &physical_plan, ClientContext &context, vector< LogicalType > types, vector< unique_ptr< Expression > > expressions, idx_t estimated_cardinality)
 PhysicalHashAggregate (PhysicalPlan &physical_plan, ClientContext &context, vector< LogicalType > types, vector< unique_ptr< Expression > > expressions, vector< unique_ptr< Expression > > groups, idx_t estimated_cardinality)
 PhysicalHashAggregate (PhysicalPlan &physical_plan, ClientContext &context, vector< LogicalType > types, vector< unique_ptr< Expression > > expressions, vector< unique_ptr< Expression > > groups, vector< GroupingSet > grouping_sets, vector< unsafe_vector< idx_t > > grouping_functions, idx_t estimated_cardinality, TupleDataValidityType group_validity, TupleDataValidityType distinct_validity)
unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const override
unique_ptr< LocalSourceState > GetLocalSourceState (ExecutionContext &context, GlobalSourceState &gstate) const override
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
ProgressData GetProgress (ClientContext &context, GlobalSourceState &gstate) const override
 Returns the current progress percentage, or a negative value if progress bars are not supported.
bool IsSource () const override
bool ParallelSource () const override
OrderPreservationType SourceOrder () const override
 The type of order emitted by the operator (as a source).
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
SinkFinalizeType FinalizeInternal (Pipeline &pipeline, Event &event, ClientContext &context, GlobalSinkState &gstate, bool check_distinct) const
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
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 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 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

Static Public Member Functions

static void SetMultiScan (GlobalSinkState &state)
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.

Public Attributes

GroupedAggregateData grouped_aggregate_data
 The grouping sets.
vector< GroupingSet > grouping_sets
vector< HashAggregateGroupingData > groupings
 The radix partitioned hash tables (one per grouping set).
unique_ptr< DistinctAggregateCollectionInfo > distinct_collection_info
vector< LogicalType > input_group_types
 A recreation of the input chunk, with nulls for everything that isnt a group.
unsafe_vector< idx_t > non_distinct_filter
 Filters given to Sink and friends.
unsafe_vector< idx_t > distinct_filter
unordered_map< Expression *, size_t > filter_indexes
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::HASH_GROUP_BY
Static Public Attributes inherited from duckdb::PhysicalOperator
static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::INVALID

Private Member Functions

bool CanSkipRegularSink () const
 When we only have distinct aggregates, we can delay adding groups to the main ht.
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 SinkDistinctGrouping (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input, idx_t grouping_idx) const
 Sink the distinct aggregates for a single grouping.
void SinkDistinct (ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const
 Sink the distinct aggregates.
SinkResultType SinkGroupsOnly (ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate, DataChunk &input) const
 Create groups in the main ht for groups that would otherwise get filtered out completely.

Detailed Description

PhysicalHashAggregate is a group-by and aggregate implementation that uses a hash table to perform the grouping This only contains read-only variables, anything that is stateful instead gets stored in the Global/Local states

Constructor & Destructor Documentation

◆ PhysicalHashAggregate() [1/3]

duckdb::PhysicalHashAggregate::PhysicalHashAggregate ( PhysicalPlan & physical_plan,
ClientContext & context,
vector< LogicalType > types,
vector< unique_ptr< Expression > > expressions,
idx_t estimated_cardinality )
160066 : PhysicalHashAggregate(physical_plan, context, std::move(types), std::move(expressions), {},
160068}
vector< LogicalType > types
The return types.
Definition duckdb.hpp:22152
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154

◆ PhysicalHashAggregate() [2/3]

duckdb::PhysicalHashAggregate::PhysicalHashAggregate ( PhysicalPlan & physical_plan,
ClientContext & context,
vector< LogicalType > types,
vector< unique_ptr< Expression > > expressions,
vector< unique_ptr< Expression > > groups,
idx_t estimated_cardinality )
160073 : PhysicalHashAggregate(physical_plan, context, std::move(types), std::move(expressions), std::move(groups_p), {},
160074 {}, estimated_cardinality, TupleDataValidityType::CAN_HAVE_NULL_VALUES,
160075 TupleDataValidityType::CAN_HAVE_NULL_VALUES) {
160076}

◆ PhysicalHashAggregate() [3/3]

duckdb::PhysicalHashAggregate::PhysicalHashAggregate ( PhysicalPlan & physical_plan,
ClientContext & context,
vector< LogicalType > types,
vector< unique_ptr< Expression > > expressions,
vector< unique_ptr< Expression > > groups,
vector< GroupingSet > grouping_sets,
vector< unsafe_vector< idx_t > > grouping_functions,
idx_t estimated_cardinality,
TupleDataValidityType group_validity,
TupleDataValidityType distinct_validity )
160085 : PhysicalOperator(physical_plan, PhysicalOperatorType::HASH_GROUP_BY, std::move(types), estimated_cardinality),
160086 grouping_sets(std::move(grouping_sets_p)) {
160087 // get a list of all aggregates to be computed
160088 const idx_t group_count = groups_p.size();
160089 if (grouping_sets.empty()) {
160090 GroupingSet set;
160091 for (idx_t i = 0; i < group_count; i++) {
160092 set.insert(i);
160093 }
160094 grouping_sets.push_back(std::move(set));
160095 }
160096 input_group_types = CreateGroupChunkTypes(groups_p);
160097
160098 grouped_aggregate_data.InitializeGroupby(std::move(groups_p), std::move(expressions),
160099 std::move(grouping_functions_p));
160100
160101 auto &aggregates = grouped_aggregate_data.aggregates;
160102 // filter_indexes must be pre-built, not lazily instantiated in parallel...
160103 // Because everything that lives in this class should be read-only at execution time
160104 idx_t aggregate_input_idx = 0;
160105 for (idx_t i = 0; i < aggregates.size(); i++) {
160106 auto &aggregate = aggregates[i];
160107 auto &aggr = aggregate->Cast<BoundAggregateExpression>();
160108 aggregate_input_idx += aggr.children.size();
160109 if (aggr.aggr_type == AggregateType::DISTINCT) {
160110 distinct_filter.push_back(i);
160111 } else if (aggr.aggr_type == AggregateType::NON_DISTINCT) {
160112 non_distinct_filter.push_back(i);
160113 } else { // LCOV_EXCL_START
160114 throw NotImplementedException("AggregateType not implemented in PhysicalHashAggregate");
160115 } // LCOV_EXCL_STOP
160116 }
160117
160118 for (idx_t i = 0; i < aggregates.size(); i++) {
160119 auto &aggregate = aggregates[i];
160120 auto &aggr = aggregate->Cast<BoundAggregateExpression>();
160121 if (aggr.filter) {
160122 auto &bound_ref_expr = aggr.filter->Cast<BoundReferenceExpression>();
160123 if (!filter_indexes.count(aggr.filter.get())) {
160124 // Replace the bound reference expression's index with the corresponding index of the payload chunk
160125 filter_indexes[aggr.filter.get()] = bound_ref_expr.index;
160126 bound_ref_expr.index = aggregate_input_idx;
160127 }
160128 aggregate_input_idx++;
160129 }
160130 }
160131
160132 distinct_collection_info = DistinctAggregateCollectionInfo::Create(grouped_aggregate_data.aggregates);
160133
160134 for (idx_t i = 0; i < grouping_sets.size(); i++) {
160135 groupings.emplace_back(grouping_sets[i], grouped_aggregate_data, distinct_collection_info, group_validity,
160136 distinct_validity);
160137 }
160138}
unsafe_vector< idx_t > non_distinct_filter
Filters given to Sink and friends.
Definition duckdb.cpp:99306
vector< LogicalType > input_group_types
A recreation of the input chunk, with nulls for everything that isnt a group.
Definition duckdb.cpp:99303
GroupedAggregateData grouped_aggregate_data
The grouping sets.
Definition duckdb.cpp:99296
vector< HashAggregateGroupingData > groupings
The radix partitioned hash tables (one per grouping set).
Definition duckdb.cpp:99300
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

160789 {
160790 return make_uniq<HashAggregateGlobalSourceState>(context, *this);
160791}

◆ GetLocalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

160807 {
160808 return make_uniq<HashAggregateLocalSourceState>(context, *this);
160809}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

160812 {
160813 auto &sink_gstate = sink_state->Cast<HashAggregateGlobalSinkState>();
160814 auto &gstate = input.global_state.Cast<HashAggregateGlobalSourceState>();
160815 auto &lstate = input.local_state.Cast<HashAggregateLocalSourceState>();
160816 while (true) {
160817 if (!lstate.radix_idx.IsValid()) {
160818 lstate.radix_idx = gstate.state_index.load();
160819 }
160820 const auto radix_idx = lstate.radix_idx.GetIndex();
160821 if (radix_idx >= groupings.size()) {
160822 break;
160823 }
160824
160825 auto &grouping = groupings[radix_idx];
160826 auto &radix_table = grouping.table_data;
160827 auto &grouping_gstate = sink_gstate.grouping_states[radix_idx];
160828
160829 OperatorSourceInput source_input {*gstate.radix_states[radix_idx], *lstate.radix_states[radix_idx],
160830 input.interrupt_state};
160831 auto res = radix_table.GetData(context, chunk, *grouping_gstate.table_state, source_input);
160832 if (res == SourceResultType::BLOCKED) {
160833 return res;
160834 }
160835 if (chunk.size() != 0) {
160836 return SourceResultType::HAVE_MORE_OUTPUT;
160837 }
160838
160839 // move to the next table
160840 auto guard = gstate.Lock();
160841 lstate.radix_idx = lstate.radix_idx.GetIndex() + 1;
160842 if (lstate.radix_idx.GetIndex() > gstate.state_index) {
160843 // we have not yet worked on the table
160844 // move the global index forwards
160845 gstate.state_index = lstate.radix_idx.GetIndex();
160846 }
160847 lstate.radix_idx = gstate.state_index.load();
160848 }
160849
160850 return chunk.size() == 0 ? SourceResultType::FINISHED : SourceResultType::HAVE_MORE_OUTPUT;
160851}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ GetProgress()

ProgressData duckdb::PhysicalHashAggregate::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.

160853 {
160854 auto &sink_gstate = sink_state->Cast<HashAggregateGlobalSinkState>();
160855 auto &gstate = gstate_p.Cast<HashAggregateGlobalSourceState>();
160856 ProgressData progress;
160857 for (idx_t radix_idx = 0; radix_idx < groupings.size(); radix_idx++) {
160858 progress.Add(groupings[radix_idx].table_data.GetProgress(
160859 context, *sink_gstate.grouping_states[radix_idx].table_state, *gstate.radix_states[radix_idx]));
160860 }
160861 return progress;
160862}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

99321 {
99322 return true;
99323 }

◆ ParallelSource()

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

Reimplemented from duckdb::PhysicalOperator.

99324 {
99325 return true;
99326 }

◆ SourceOrder()

OrderPreservationType duckdb::PhysicalHashAggregate::SourceOrder ( ) const
inlineoverridevirtual

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

Reimplemented from duckdb::PhysicalOperator.

99328 {
99329 return OrderPreservationType::NO_ORDER;
99330 }

◆ Sink()

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

160307 {
160308 auto &local_state = input.local_state.Cast<HashAggregateLocalSinkState>();
160309 auto &global_state = input.global_state.Cast<HashAggregateGlobalSinkState>();
160310
160311 if (distinct_collection_info) {
160312 SinkDistinct(context, chunk, input);
160313 }
160314
160315 if (CanSkipRegularSink()) {
160316 return SinkResultType::NEED_MORE_INPUT;
160317 }
160318
160319 DataChunk &aggregate_input_chunk = local_state.aggregate_input_chunk;
160320 auto &aggregates = grouped_aggregate_data.aggregates;
160321 idx_t aggregate_input_idx = 0;
160322
160323 // Populate the aggregate child vectors
160324 for (auto &aggregate : aggregates) {
160325 auto &aggr = aggregate->Cast<BoundAggregateExpression>();
160326 for (auto &child_expr : aggr.children) {
160327 D_ASSERT(child_expr->GetExpressionType() == ExpressionType::BOUND_REF);
160328 auto &bound_ref_expr = child_expr->Cast<BoundReferenceExpression>();
160329 D_ASSERT(bound_ref_expr.index < chunk.data.size());
160330 aggregate_input_chunk.data[aggregate_input_idx++].Reference(chunk.data[bound_ref_expr.index]);
160331 }
160332 }
160333 // Populate the filter vectors
160334 for (auto &aggregate : aggregates) {
160335 auto &aggr = aggregate->Cast<BoundAggregateExpression>();
160336 if (aggr.filter) {
160337 auto it = filter_indexes.find(aggr.filter.get());
160338 D_ASSERT(it != filter_indexes.end());
160339 D_ASSERT(it->second < chunk.data.size());
160340 aggregate_input_chunk.data[aggregate_input_idx++].Reference(chunk.data[it->second]);
160341 }
160342 }
160343
160344 aggregate_input_chunk.SetCardinality(chunk.size());
160345 aggregate_input_chunk.Verify();
160346
160347 // For every grouping set there is one radix_table
160348 for (idx_t i = 0; i < groupings.size(); i++) {
160349 auto &grouping_global_state = global_state.grouping_states[i];
160350 auto &grouping_local_state = local_state.grouping_states[i];
160351 InterruptState interrupt_state;
160352 OperatorSinkInput sink_input {*grouping_global_state.table_state, *grouping_local_state.table_state,
160353 interrupt_state};
160354
160355 auto &grouping = groupings[i];
160356 auto &table = grouping.table_data;
160357 table.Sink(context, chunk, sink_input, aggregate_input_chunk, non_distinct_filter);
160358 }
160359
160360 return SinkResultType::NEED_MORE_INPUT;
160361}
DUCKDB_API void Verify()
Definition duckdb.cpp:117115
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
void SinkDistinct(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const
Sink the distinct aggregates.
Definition duckdb.cpp:160300
bool CanSkipRegularSink() const
When we only have distinct aggregates, we can delay adding groups to the main ht.
Definition duckdb.cpp:160048
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Combine()

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

160394 {
160395 auto &gstate = input.global_state.Cast<HashAggregateGlobalSinkState>();
160396 auto &llstate = input.local_state.Cast<HashAggregateLocalSinkState>();
160397
160398 OperatorSinkCombineInput combine_distinct_input {gstate, llstate, input.interrupt_state};
160399 CombineDistinct(context, combine_distinct_input);
160400
160401 if (CanSkipRegularSink()) {
160402 return SinkCombineResultType::FINISHED;
160403 }
160404 for (idx_t i = 0; i < groupings.size(); i++) {
160405 auto &grouping_gstate = gstate.grouping_states[i];
160406 auto &grouping_lstate = llstate.grouping_states[i];
160407
160408 auto &grouping = groupings[i];
160409 auto &table = grouping.table_data;
160410 table.Combine(context, *grouping_gstate.table_state, *grouping_lstate.table_state);
160411 }
160412
160413 return SinkCombineResultType::FINISHED;
160414}
void CombineDistinct(ExecutionContext &context, OperatorSinkCombineInput &input) const
Combine the distinct aggregates.
Definition duckdb.cpp:160366
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Finalize()

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

160750 {
160751 return FinalizeInternal(pipeline, event, context, input.global_state, true);
160752}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FinalizeInternal()

SinkFinalizeType duckdb::PhysicalHashAggregate::FinalizeInternal ( Pipeline & pipeline,
Event & event,
ClientContext & context,
GlobalSinkState & gstate,
bool check_distinct ) const
160731 {
160732 auto &gstate = gstate_p.Cast<HashAggregateGlobalSinkState>();
160733
160734 if (check_distinct && distinct_collection_info) {
160735 // There are distinct aggregates
160736 // If these are partitioned those need to be combined first
160737 // Then we Finalize again, skipping this step
160738 return FinalizeDistinct(pipeline, event, context, gstate_p);
160739 }
160740
160741 for (idx_t i = 0; i < groupings.size(); i++) {
160742 auto &grouping = groupings[i];
160743 auto &grouping_gstate = gstate.grouping_states[i];
160744 grouping.table_data.Finalize(context, *grouping_gstate.table_state);
160745 }
160746 return SinkFinalizeType::READY;
160747}
SinkFinalizeType FinalizeDistinct(Pipeline &pipeline, Event &event, ClientContext &context, GlobalSinkState &gstate) const
Finalize the distinct aggregates.
Definition duckdb.cpp:160706

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

160213 {
160214 return make_uniq<HashAggregateLocalSinkState>(*this, context);
160215}

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

160209 {
160210 return make_uniq<HashAggregateGlobalSinkState>(*this, context);
160211}

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

99344 {
99345 return true;
99346 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

99348 {
99349 return true;
99350 }

◆ SinkOrderDependent()

bool duckdb::PhysicalHashAggregate::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.

99352 {
99353 return false;
99354 }

◆ ParamsToString()

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

Reimplemented from duckdb::PhysicalOperator.

160864 {
160865 InsertionOrderPreservingMap<string> result;
160866 auto &groups = grouped_aggregate_data.groups;
160867 auto &aggregates = grouped_aggregate_data.aggregates;
160868 string groups_info;
160869 for (idx_t i = 0; i < groups.size(); i++) {
160870 if (i > 0) {
160871 groups_info += "\n";
160872 }
160873 groups_info += groups[i]->GetName();
160874 }
160875 result["Groups"] = groups_info;
160876
160877 string aggregate_info;
160878 for (idx_t i = 0; i < aggregates.size(); i++) {
160879 auto &aggregate = aggregates[i]->Cast<BoundAggregateExpression>();
160880 if (i > 0) {
160881 aggregate_info += "\n";
160882 }
160883 aggregate_info += aggregates[i]->GetName();
160884 if (aggregate.filter) {
160885 aggregate_info += " Filter: " + aggregate.filter->GetName();
160886 }
160887 }
160888 result["Aggregates"] = aggregate_info;
160889 SetEstimatedCardinality(result, estimated_cardinality);
160890 return result;
160891}

◆ SetMultiScan()

void duckdb::PhysicalHashAggregate::SetMultiScan ( GlobalSinkState & state)
static

Toggle multi-scan capability on a hash table, which prevents the scan of the aggregate from being destructive If this is not toggled the GetData method will destroy the hash table as it is scanning it

160199 {
160200 auto &gstate = state.Cast<HashAggregateGlobalSinkState>();
160201 for (auto &grouping_state : gstate.grouping_states) {
160202 RadixPartitionedHashTable::SetMultiScan(*grouping_state.table_state);
160203 }
160204}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CanSkipRegularSink()

bool duckdb::PhysicalHashAggregate::CanSkipRegularSink ( ) const
private

When we only have distinct aggregates, we can delay adding groups to the main ht.

160048 {
160049 if (!filter_indexes.empty()) {
160050 // If we have filters, we can't skip the regular sink, because we might lose groups otherwise.
160051 return false;
160052 }
160053 if (grouped_aggregate_data.aggregates.empty()) {
160054 // When there are no aggregates, we have to add to the main ht right away
160055 return false;
160056 }
160057 if (!non_distinct_filter.empty()) {
160058 return false;
160059 }
160060 return true;
160061}
Here is the caller graph for this function:

◆ FinalizeDistinct()

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

Finalize the distinct aggregates.

160707 {
160708 auto &gstate = gstate_p.Cast<HashAggregateGlobalSinkState>();
160709 D_ASSERT(distinct_collection_info);
160710
160711 for (idx_t i = 0; i < groupings.size(); i++) {
160712 auto &grouping = groupings[i];
160713 auto &distinct_data = *grouping.distinct_data;
160714 auto &distinct_state = *gstate.grouping_states[i].distinct_state;
160715
160716 for (idx_t table_idx = 0; table_idx < distinct_data.radix_tables.size(); table_idx++) {
160717 if (!distinct_data.radix_tables[table_idx]) {
160718 continue;
160719 }
160720 auto &radix_table = distinct_data.radix_tables[table_idx];
160721 auto &radix_state = *distinct_state.radix_states[table_idx];
160722 radix_table->Finalize(context, radix_state);
160723 }
160724 }
160725 auto new_event = make_shared_ptr<HashAggregateDistinctFinalizeEvent>(context, pipeline, *this, gstate);
160726 event.InsertEvent(std::move(new_event));
160727 return SinkFinalizeType::READY;
160728}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CombineDistinct()

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

Combine the distinct aggregates.

160366 {
160367 auto &global_sink = input.global_state.Cast<HashAggregateGlobalSinkState>();
160368 auto &sink = input.local_state.Cast<HashAggregateLocalSinkState>();
160369
160370 if (!distinct_collection_info) {
160371 return;
160372 }
160373 for (idx_t i = 0; i < groupings.size(); i++) {
160374 auto &grouping_gstate = global_sink.grouping_states[i];
160375 auto &grouping_lstate = sink.grouping_states[i];
160376
160377 auto &distinct_data = groupings[i].distinct_data;
160378 auto &distinct_state = grouping_gstate.distinct_state;
160379
160380 const auto table_count = distinct_data->radix_tables.size();
160381 for (idx_t table_idx = 0; table_idx < table_count; table_idx++) {
160382 if (!distinct_data->radix_tables[table_idx]) {
160383 continue;
160384 }
160385 auto &radix_table = *distinct_data->radix_tables[table_idx];
160386 auto &radix_global_sink = *distinct_state->radix_states[table_idx];
160387 auto &radix_local_sink = *grouping_lstate.distinct_states[table_idx];
160388
160389 radix_table.Combine(context, radix_global_sink, radix_local_sink);
160390 }
160391 }
160392}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SinkDistinctGrouping()

void duckdb::PhysicalHashAggregate::SinkDistinctGrouping ( ExecutionContext & context,
DataChunk & chunk,
OperatorSinkInput & input,
idx_t grouping_idx ) const
private

Sink the distinct aggregates for a single grouping.

160218 {
160219 auto &sink = input.local_state.Cast<HashAggregateLocalSinkState>();
160220 auto &global_sink = input.global_state.Cast<HashAggregateGlobalSinkState>();
160221
160222 auto &grouping_gstate = global_sink.grouping_states[grouping_idx];
160223 auto &grouping_lstate = sink.grouping_states[grouping_idx];
160224 auto &distinct_info = *distinct_collection_info;
160225
160226 auto &distinct_state = grouping_gstate.distinct_state;
160227 auto &distinct_data = groupings[grouping_idx].distinct_data;
160228
160229 DataChunk empty_chunk;
160230
160231 // Create an empty filter for Sink, since we don't need to update any aggregate states here
160232 unsafe_vector<idx_t> empty_filter;
160233
160234 for (idx_t &idx : distinct_info.indices) {
160235 auto &aggregate = grouped_aggregate_data.aggregates[idx]->Cast<BoundAggregateExpression>();
160236
160237 D_ASSERT(distinct_info.table_map.count(idx));
160238 idx_t table_idx = distinct_info.table_map[idx];
160239 if (!distinct_data->radix_tables[table_idx]) {
160240 continue;
160241 }
160242 D_ASSERT(distinct_data->radix_tables[table_idx]);
160243 auto &radix_table = *distinct_data->radix_tables[table_idx];
160244 auto &radix_global_sink = *distinct_state->radix_states[table_idx];
160245 auto &radix_local_sink = *grouping_lstate.distinct_states[table_idx];
160246
160247 InterruptState interrupt_state;
160248 OperatorSinkInput sink_input {radix_global_sink, radix_local_sink, interrupt_state};
160249
160250 if (aggregate.filter) {
160251 DataChunk filter_chunk;
160252 auto &filtered_data = sink.filter_set.GetFilterData(idx);
160253 filter_chunk.InitializeEmpty(filtered_data.filtered_payload.GetTypes());
160254
160255 // Add the filter Vector (BOOL)
160256 auto it = filter_indexes.find(aggregate.filter.get());
160257 D_ASSERT(it != filter_indexes.end());
160258 D_ASSERT(it->second < chunk.data.size());
160259 auto &filter_bound_ref = aggregate.filter->Cast<BoundReferenceExpression>();
160260 filter_chunk.data[filter_bound_ref.index].Reference(chunk.data[it->second]);
160261 filter_chunk.SetCardinality(chunk.size());
160262
160263 // We cant use the AggregateFilterData::ApplyFilter method, because the chunk we need to
160264 // apply the filter to also has the groups, and the filtered_data.filtered_payload does not have those.
160265 SelectionVector sel_vec(STANDARD_VECTOR_SIZE);
160266 idx_t count = filtered_data.filter_executor.SelectExpression(filter_chunk, sel_vec);
160267
160268 if (count == 0) {
160269 continue;
160270 }
160271
160272 // Because the 'input' chunk needs to be re-used after this, we need to create
160273 // a duplicate of it, that we can apply the filter to
160274 DataChunk filtered_input;
160275 filtered_input.InitializeEmpty(chunk.GetTypes());
160276
160277 for (idx_t group_idx = 0; group_idx < grouped_aggregate_data.groups.size(); group_idx++) {
160278 auto &group = grouped_aggregate_data.groups[group_idx];
160279 auto &bound_ref = group->Cast<BoundReferenceExpression>();
160280 auto &col = filtered_input.data[bound_ref.index];
160281 col.Reference(chunk.data[bound_ref.index]);
160282 col.Slice(sel_vec, count);
160283 }
160284 for (idx_t child_idx = 0; child_idx < aggregate.children.size(); child_idx++) {
160285 auto &child = aggregate.children[child_idx];
160286 auto &bound_ref = child->Cast<BoundReferenceExpression>();
160287 auto &col = filtered_input.data[bound_ref.index];
160288 col.Reference(chunk.data[bound_ref.index]);
160289 col.Slice(sel_vec, count);
160290 }
160291 filtered_input.SetCardinality(count);
160292
160293 radix_table.Sink(context, filtered_input, sink_input, empty_chunk, empty_filter);
160294 } else {
160295 radix_table.Sink(context, chunk, sink_input, empty_chunk, empty_filter);
160296 }
160297 }
160298}
DUCKDB_API void InitializeEmpty(const vector< LogicalType > &types)
Initializes a DataChunk with the given types and without any vector data allocation.
Definition duckdb.cpp:116783
DUCKDB_API vector< LogicalType > GetTypes() const
Returns a list of types of the vectors of this data chunk.
Definition duckdb.cpp:116995
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SinkDistinct()

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

Sink the distinct aggregates.

160300 {
160301 for (idx_t i = 0; i < groupings.size(); i++) {
160302 SinkDistinctGrouping(context, chunk, input, i);
160303 }
160304}
void SinkDistinctGrouping(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input, idx_t grouping_idx) const
Sink the distinct aggregates for a single grouping.
Definition duckdb.cpp:160217
Here is the call graph for this function:
Here is the caller graph for this function:

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