//===----------------------------------------------------------------------===// // DuckDB // // duckdb/execution/operator/aggregate/physical_ungrouped_aggregate.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/execution/physical_operator.hpp" #include "duckdb/planner/expression.hpp" #include "duckdb/execution/operator/aggregate/grouped_aggregate_data.hpp" #include "duckdb/execution/operator/aggregate/distinct_aggregate_data.hpp" #include "duckdb/parser/group_by_node.hpp" #include "duckdb/execution/radix_partitioned_hashtable.hpp" #include "duckdb/common/unordered_map.hpp" namespace duckdb { //! PhysicalUngroupedAggregate is an aggregate operator that can only perform aggregates (1) without any groups, (2) //! without any DISTINCT aggregates, and (3) when all aggregates are combineable class PhysicalUngroupedAggregate : public PhysicalOperator { public: static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::UNGROUPED_AGGREGATE; public: PhysicalUngroupedAggregate(vector types, vector> expressions, idx_t estimated_cardinality); //! The aggregates that have to be computed vector> aggregates; unique_ptr distinct_data; unique_ptr distinct_collection_info; public: // Source interface SourceResultType GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override; bool IsSource() const override { return true; } public: // Sink interface SinkResultType Sink(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const override; void Combine(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate) const override; SinkFinalizeType Finalize(Pipeline &pipeline, Event &event, ClientContext &context, GlobalSinkState &gstate) const override; unique_ptr GetLocalSinkState(ExecutionContext &context) const override; unique_ptr GetGlobalSinkState(ClientContext &context) const override; string ParamsToString() const override; bool IsSink() const override { return true; } bool ParallelSink() const override { return true; } bool SinkOrderDependent() const override; private: //! Finalize the distinct aggregates SinkFinalizeType FinalizeDistinct(Pipeline &pipeline, Event &event, ClientContext &context, GlobalSinkState &gstate) const; //! Combine the distinct aggregates void CombineDistinct(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate) const; //! Sink the distinct aggregates void SinkDistinct(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const; }; } // namespace duckdb