1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/execution/radix_partitioned_hashtable.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/execution/partitionable_hashtable.hpp" |
12 | #include "duckdb/parser/group_by_node.hpp" |
13 | #include "duckdb/execution/physical_operator.hpp" |
14 | #include "duckdb/execution/operator/aggregate/grouped_aggregate_data.hpp" |
15 | |
16 | namespace duckdb { |
17 | class BufferManager; |
18 | class Executor; |
19 | class PhysicalHashAggregate; |
20 | class Pipeline; |
21 | class Task; |
22 | |
23 | class RadixPartitionedHashTable { |
24 | public: |
25 | RadixPartitionedHashTable(GroupingSet &grouping_set, const GroupedAggregateData &op); |
26 | |
27 | GroupingSet &grouping_set; |
28 | //! The indices specified in the groups_count that do not appear in the grouping_set |
29 | unsafe_vector<idx_t> null_groups; |
30 | const GroupedAggregateData &op; |
31 | |
32 | vector<LogicalType> group_types; |
33 | //! how many groups can we have in the operator before we switch to radix partitioning |
34 | idx_t radix_limit; |
35 | |
36 | //! The GROUPING values that belong to this hash table |
37 | vector<Value> grouping_values; |
38 | |
39 | public: |
40 | //! Sink Interface |
41 | unique_ptr<GlobalSinkState> GetGlobalSinkState(ClientContext &context) const; |
42 | unique_ptr<LocalSinkState> GetLocalSinkState(ExecutionContext &context) const; |
43 | |
44 | void Sink(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input, DataChunk &aggregate_input_chunk, |
45 | const unsafe_vector<idx_t> &filter) const; |
46 | void Combine(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate) const; |
47 | bool Finalize(ClientContext &context, GlobalSinkState &gstate_p) const; |
48 | |
49 | void ScheduleTasks(Executor &executor, const shared_ptr<Event> &event, GlobalSinkState &state, |
50 | vector<shared_ptr<Task>> &tasks) const; |
51 | |
52 | //! Source interface |
53 | idx_t Size(GlobalSinkState &sink_state) const; |
54 | unique_ptr<GlobalSourceState> GetGlobalSourceState(ClientContext &context) const; |
55 | unique_ptr<LocalSourceState> GetLocalSourceState(ExecutionContext &context) const; |
56 | SourceResultType GetData(ExecutionContext &context, DataChunk &chunk, GlobalSinkState &sink_state, |
57 | OperatorSourceInput &input) const; |
58 | |
59 | static void SetMultiScan(GlobalSinkState &state); |
60 | bool ForceSingleHT(GlobalSinkState &state) const; |
61 | |
62 | private: |
63 | void SetGroupingValues(); |
64 | void PopulateGroupChunk(DataChunk &group_chunk, DataChunk &input_chunk) const; |
65 | }; |
66 | |
67 | } // namespace duckdb |
68 | |