13#include "common/lang/vector.h"
14#include "common/lang/unordered_map.h"
15#include "common/math/simd_util.h"
16#include "common/sys/rc.h"
17#include "sql/expr/expression.h"
31 virtual void open_scan() = 0;
38 virtual void close_scan() {}
50 vector<AggregateExpr::Type> aggr_types_;
51 vector<AttrType> aggr_child_types_;
59 size_t operator()(
const vector<Value> &vec)
const;
64 bool operator()(
const vector<Value> &lhs,
const vector<Value> &rhs)
const;
75 void open_scan()
override;
80 StandardHashTable::iterator end_;
81 StandardHashTable::iterator it_;
85 for (
auto &expr : aggregations) {
86 ASSERT(expr->type() == ExprType::AGGREGATION,
"expect aggregate expression");
88 aggr_types_.push_back(aggregation_expr->aggregate_type());
89 aggr_child_types_.push_back(aggregation_expr->value_type());
95 for (
auto &state : aggr.second) {
103 StandardHashTable::iterator begin() {
return aggr_values_.begin(); }
104 StandardHashTable::iterator end() {
return aggr_values_.end(); }
123 ~Scanner() =
default;
125 void open_scan()
override;
127 RC next(
Chunk &chunk)
override;
129 void close_scan()
override;
138 LinearProbingAggregateHashTable(AggregateExpr::Type aggregate_type,
int capacity = DEFAULT_CAPACITY)
139 : keys_(capacity, EMPTY_KEY), values_(capacity, 0), capacity_(capacity), aggregate_type_(aggregate_type)
141 virtual ~LinearProbingAggregateHashTable() {}
143 RC get(
int key, V &value);
145 RC iter_get(
int pos,
int &key, V &value);
149 int capacity() {
return capacity_; }
150 int size() {
return size_; }
160 void add_batch(
int *input_keys, V *input_values,
int len);
162 void aggregate(V *value, V value_to_aggregate);
166 void resize_if_need();
169 static const int EMPTY_KEY;
170 static const int DEFAULT_CAPACITY;
176 AggregateExpr::Type aggregate_type_;
Definition: expression.h:469
Definition: aggregate_hash_table.h:26
virtual RC next(Chunk &chunk)=0
用于hash group by 的哈希表实现,不支持并发访问。
Definition: aggregate_hash_table.h:23
virtual RC add_chunk(Chunk &groups_chunk, Chunk &aggrs_chunk)=0
将 groups_chunk 和 aggrs_chunk 写入到哈希表中。哈希表中记录了聚合结果。
A Chunk represents a set of columns.
Definition: chunk.h:23
Definition: aggregate_hash_table.h:70
RC next(Chunk &chunk) override
Definition: aggregate_hash_table.cpp:60
Definition: aggregate_hash_table.h:55
StandardHashTable aggr_values_
group by values -> aggregate values
Definition: aggregate_hash_table.h:107
RC add_chunk(Chunk &groups_chunk, Chunk &aggrs_chunk) override
将 groups_chunk 和 aggrs_chunk 写入到哈希表中。哈希表中记录了聚合结果。
Definition: aggregate_hash_table.cpp:16
Definition: aggregate_hash_table.h:63
Definition: aggregate_hash_table.h:58