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

PhysicalPerfectHashAggregate performs a group-by and aggregation using a perfect hash table. More...

Inheritance diagram for duckdb::PhysicalPerfectHashAggregate:
Collaboration diagram for duckdb::PhysicalPerfectHashAggregate:

Public Member Functions

 PhysicalPerfectHashAggregate (PhysicalPlan &physical_plan, ClientContext &context, vector< LogicalType > types, vector< unique_ptr< Expression > > aggregates, vector< unique_ptr< Expression > > groups, const vector< unique_ptr< BaseStatistics > > &group_stats, vector< idx_t > required_bits, idx_t estimated_cardinality)
unique_ptr< GlobalSourceState > GetGlobalSourceState (ClientContext &context) const override
SourceResultType GetDataInternal (ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override
bool IsSource () 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
unique_ptr< LocalSinkState > GetLocalSinkState (ExecutionContext &context) const override
unique_ptr< GlobalSinkState > GetGlobalSinkState (ClientContext &context) const override
InsertionOrderPreservingMap< string > ParamsToString () const override
unique_ptr< PerfectAggregateHashTable > CreateHT (Allocator &allocator, ClientContext &context) const
 Create a perfect aggregate hash table for this node.
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
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 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 SinkFinalizeType Finalize (Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) 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 > > groups
 The groups.
vector< unique_ptr< Expression > > aggregates
 The aggregates that have to be computed.
vector< LogicalType > group_types
 The group types.
vector< LogicalType > payload_types
 The payload types.
vector< AggregateObject > aggregate_objects
 The aggregates to be computed.
vector< Value > group_minima
 The minimum value of each of the groups.
vector< idx_t > required_bits
 The number of bits we need to completely cover each of the groups.
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::PERFECT_HASH_GROUP_BY
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

PhysicalPerfectHashAggregate performs a group-by and aggregation using a perfect hash table.

Constructor & Destructor Documentation

◆ PhysicalPerfectHashAggregate()

duckdb::PhysicalPerfectHashAggregate::PhysicalPerfectHashAggregate ( PhysicalPlan & physical_plan,
ClientContext & context,
vector< LogicalType > types,
vector< unique_ptr< Expression > > aggregates,
vector< unique_ptr< Expression > > groups,
const vector< unique_ptr< BaseStatistics > > & group_stats,
vector< idx_t > required_bits,
idx_t estimated_cardinality )
161459 : PhysicalOperator(physical_plan, PhysicalOperatorType::PERFECT_HASH_GROUP_BY, std::move(types_p),
161461 groups(std::move(groups_p)), aggregates(std::move(aggregates_p)), required_bits(std::move(required_bits_p)) {
161462 D_ASSERT(groups.size() == group_stats.size());
161463 group_minima.reserve(group_stats.size());
161464 for (auto &stats : group_stats) {
161465 D_ASSERT(stats);
161466 auto &nstats = *stats;
161467 D_ASSERT(NumericStats::HasMin(nstats));
161468 group_minima.push_back(NumericStats::Min(nstats));
161469 }
161470 for (auto &expr : groups) {
161471 group_types.push_back(expr->return_type);
161472 }
161473
161474 vector<BoundAggregateExpression *> bindings;
161475 vector<LogicalType> payload_types_filters;
161476 for (auto &expr : aggregates) {
161477 D_ASSERT(expr->GetExpressionClass() == ExpressionClass::BOUND_AGGREGATE);
161478 D_ASSERT(expr->IsAggregate());
161479 auto &aggr = expr->Cast<BoundAggregateExpression>();
161480 bindings.push_back(&aggr);
161481
161482 D_ASSERT(!aggr.IsDistinct());
161483 D_ASSERT(aggr.function.HasStateCombineCallback());
161484 for (auto &child : aggr.children) {
161485 payload_types.push_back(child->return_type);
161486 }
161487 if (aggr.filter) {
161488 payload_types_filters.push_back(aggr.filter->return_type);
161489 }
161490 }
161491 for (const auto &pay_filters : payload_types_filters) {
161492 payload_types.push_back(pay_filters);
161493 }
161494 aggregate_objects = AggregateObject::CreateAggregateObjects(bindings);
161495
161496 // filter_indexes must be pre-built, not lazily instantiated in parallel...
161497 idx_t aggregate_input_idx = 0;
161498 for (auto &aggregate : aggregates) {
161499 auto &aggr = aggregate->Cast<BoundAggregateExpression>();
161500 aggregate_input_idx += aggr.children.size();
161501 }
161502 for (auto &aggregate : aggregates) {
161503 auto &aggr = aggregate->Cast<BoundAggregateExpression>();
161504 if (aggr.filter) {
161505 auto &bound_ref_expr = aggr.filter->Cast<BoundReferenceExpression>();
161506 auto it = filter_indexes.find(aggr.filter.get());
161507 if (it == filter_indexes.end()) {
161508 filter_indexes[aggr.filter.get()] = bound_ref_expr.index;
161509 bound_ref_expr.index = aggregate_input_idx++;
161510 } else {
161511 ++aggregate_input_idx;
161512 }
161513 }
161514 }
161515}
idx_t estimated_cardinality
The estimated cardinality.
Definition duckdb.hpp:22154
vector< unique_ptr< Expression > > groups
The groups.
Definition duckdb.cpp:161317
vector< AggregateObject > aggregate_objects
The aggregates to be computed.
Definition duckdb.cpp:161365
vector< idx_t > required_bits
The number of bits we need to completely cover each of the groups.
Definition duckdb.cpp:161369
vector< unique_ptr< Expression > > aggregates
The aggregates that have to be computed.
Definition duckdb.cpp:161319
vector< LogicalType > payload_types
The payload types.
Definition duckdb.cpp:161363
vector< LogicalType > group_types
The group types.
Definition duckdb.cpp:161361
vector< Value > group_minima
The minimum value of each of the groups.
Definition duckdb.cpp:161367
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API bool HasMin(const BaseStatistics &stats)
Returns true if the stats has a min value defined.
Definition duckdb.cpp:424242
static DUCKDB_API Value Min(const BaseStatistics &stats)
Returns the min value - throws an exception if there is no min value.
Definition duckdb.cpp:424256

Member Function Documentation

◆ GetGlobalSourceState()

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

Reimplemented from duckdb::PhysicalOperator.

161630 {
161631 return make_uniq<PerfectHashAggregateState>();
161632}

◆ GetDataInternal()

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

Reimplemented from duckdb::PhysicalOperator.

161635 {
161636 auto &state = input.global_state.Cast<PerfectHashAggregateState>();
161637 auto &gstate = sink_state->Cast<PerfectHashAggregateGlobalState>();
161638
161639 gstate.ht->Scan(state.ht_scan_position, chunk);
161640
161641 if (chunk.size() > 0) {
161642 return SourceResultType::HAVE_MORE_OUTPUT;
161643 } else {
161644 return SourceResultType::FINISHED;
161645 }
161646}
unique_ptr< GlobalSinkState > sink_state
The global sink state.
Definition duckdb.hpp:22157

◆ IsSource()

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

Reimplemented from duckdb::PhysicalOperator.

161327 {
161328 return true;
161329 }

◆ SourceOrder()

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

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

Reimplemented from duckdb::PhysicalOperator.

161330 {
161331 return OrderPreservationType::NO_ORDER;
161332 }

◆ Sink()

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

161563 {
161564 auto &lstate = input.local_state.Cast<PerfectHashAggregateLocalState>();
161565 DataChunk &group_chunk = lstate.group_chunk;
161566 DataChunk &aggregate_input_chunk = lstate.aggregate_input_chunk;
161567
161568 for (idx_t group_idx = 0; group_idx < groups.size(); group_idx++) {
161569 auto &group = groups[group_idx];
161570 D_ASSERT(group->GetExpressionType() == ExpressionType::BOUND_REF);
161571 auto &bound_ref_expr = group->Cast<BoundReferenceExpression>();
161572 group_chunk.data[group_idx].Reference(chunk.data[bound_ref_expr.index]);
161573 }
161574 idx_t aggregate_input_idx = 0;
161575 for (auto &aggregate : aggregates) {
161576 auto &aggr = aggregate->Cast<BoundAggregateExpression>();
161577 for (auto &child_expr : aggr.children) {
161578 D_ASSERT(child_expr->GetExpressionType() == ExpressionType::BOUND_REF);
161579 auto &bound_ref_expr = child_expr->Cast<BoundReferenceExpression>();
161580 aggregate_input_chunk.data[aggregate_input_idx++].Reference(chunk.data[bound_ref_expr.index]);
161581 }
161582 }
161583 for (auto &aggregate : aggregates) {
161584 auto &aggr = aggregate->Cast<BoundAggregateExpression>();
161585 if (aggr.filter) {
161586 auto it = filter_indexes.find(aggr.filter.get());
161587 D_ASSERT(it != filter_indexes.end());
161588 aggregate_input_chunk.data[aggregate_input_idx++].Reference(chunk.data[it->second]);
161589 }
161590 }
161591
161592 group_chunk.SetCardinality(chunk.size());
161593
161594 aggregate_input_chunk.SetCardinality(chunk.size());
161595
161596 group_chunk.Verify();
161597 aggregate_input_chunk.Verify();
161598 D_ASSERT(aggregate_input_chunk.ColumnCount() == 0 || group_chunk.size() == aggregate_input_chunk.size());
161599
161600 lstate.ht->AddChunk(group_chunk, aggregate_input_chunk);
161601 return SinkResultType::NEED_MORE_INPUT;
161602}
DUCKDB_API void Verify()
Definition duckdb.cpp:117115
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
Here is the call graph for this function:

◆ Combine()

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

161608 {
161609 auto &lstate = input.local_state.Cast<PerfectHashAggregateLocalState>();
161610 auto &gstate = input.global_state.Cast<PerfectHashAggregateGlobalState>();
161611
161612 lock_guard<mutex> l(gstate.lock);
161613 gstate.ht->Combine(*lstate.ht);
161614
161615 return SinkCombineResultType::FINISHED;
161616}

◆ GetLocalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

161558 {
161559 return make_uniq<PerfectHashAggregateLocalState>(*this, context);
161560}

◆ GetGlobalSinkState()

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

Reimplemented from duckdb::PhysicalOperator.

161554 {
161555 return make_uniq<PerfectHashAggregateGlobalState>(*this, context);
161556}

◆ ParamsToString()

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

Reimplemented from duckdb::PhysicalOperator.

161648 {
161649 InsertionOrderPreservingMap<string> result;
161650 string groups_info;
161651 for (idx_t i = 0; i < groups.size(); i++) {
161652 if (i > 0) {
161653 groups_info += "\n";
161654 }
161655 groups_info += groups[i]->GetName();
161656 }
161657 result["Groups"] = groups_info;
161658
161659 string aggregate_info;
161660 for (idx_t i = 0; i < aggregates.size(); i++) {
161661 if (i > 0) {
161662 aggregate_info += "\n";
161663 }
161664 aggregate_info += aggregates[i]->GetName();
161665 auto &aggregate = aggregates[i]->Cast<BoundAggregateExpression>();
161666 if (aggregate.filter) {
161667 aggregate_info += " Filter: " + aggregate.filter->GetName();
161668 }
161669 }
161670 result["Aggregates"] = aggregate_info;
161671 return result;
161672}

◆ CreateHT()

unique_ptr< PerfectAggregateHashTable > duckdb::PhysicalPerfectHashAggregate::CreateHT ( Allocator & allocator,
ClientContext & context ) const

Create a perfect aggregate hash table for this node.

161518 {
161519 return make_uniq<PerfectAggregateHashTable>(context, allocator, group_types, payload_types, aggregate_objects,
161521}

◆ IsSink()

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

Reimplemented from duckdb::PhysicalOperator.

161347 {
161348 return true;
161349 }

◆ ParallelSink()

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

Reimplemented from duckdb::PhysicalOperator.

161351 {
161352 return true;
161353 }

◆ SinkOrderDependent()

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

161355 {
161356 return false;
161357 }

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