//===----------------------------------------------------------------------===// // DuckDB // // duckdb/execution/operator/aggregate/grouped_aggregate_data.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/execution/operator/aggregate/grouped_aggregate_data.hpp" #include "duckdb/execution/radix_partitioned_hashtable.hpp" namespace duckdb { class GroupedAggregateData; struct DistinctAggregateCollectionInfo { public: DistinctAggregateCollectionInfo(const vector> &aggregates, vector indices); public: // The indices of the aggregates that are distinct unsafe_vector indices; // The amount of radix_tables that are occupied idx_t table_count; //! Occupied tables, not equal to indices if aggregates share input data vector table_indices; //! This indirection is used to allow two aggregates to share the same input data unordered_map table_map; const vector> &aggregates; // Total amount of children of the distinct aggregates idx_t total_child_count; public: static unique_ptr Create(vector> &aggregates); const unsafe_vector &Indices() const; bool AnyDistinct() const; private: //! Returns the amount of tables that are occupied idx_t CreateTableIndexMap(); }; struct DistinctAggregateData { public: DistinctAggregateData(const DistinctAggregateCollectionInfo &info); DistinctAggregateData(const DistinctAggregateCollectionInfo &info, const GroupingSet &groups, const vector> *group_expressions); //! The data used by the hashtables vector> grouped_aggregate_data; //! The hashtables vector> radix_tables; //! The groups (arguments) vector grouping_sets; const DistinctAggregateCollectionInfo &info; public: bool IsDistinct(idx_t index) const; }; struct DistinctAggregateState { public: DistinctAggregateState(const DistinctAggregateData &data, ClientContext &client); //! The executor ExpressionExecutor child_executor; //! The global sink states of the hash tables vector> radix_states; //! Output chunks to receive distinct data from hashtables vector> distinct_output_chunks; }; } // namespace duckdb