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(){};
57 size_t operator()(
const vector<Value> &vec)
const;
62 bool operator()(
const vector<Value> &lhs,
const vector<Value> &rhs)
const;
73 void open_scan()
override;
78 StandardHashTable::iterator end_;
79 StandardHashTable::iterator it_;
83 for (
auto &expr : aggregations) {
84 ASSERT(expr->type() == ExprType::AGGREGATION,
"expect aggregate expression");
86 aggr_types_.push_back(aggregation_expr->aggregate_type());
94 StandardHashTable::iterator begin() {
return aggr_values_.begin(); }
95 StandardHashTable::iterator end() {
return aggr_values_.end(); }
100 vector<AggregateExpr::Type> aggr_types_;
116 ~Scanner() =
default;
118 void open_scan()
override;
120 RC next(
Chunk &chunk)
override;
122 void close_scan()
override;
131 LinearProbingAggregateHashTable(AggregateExpr::Type aggregate_type,
int capacity = DEFAULT_CAPACITY)
132 : keys_(capacity, EMPTY_KEY), values_(capacity, 0), capacity_(capacity), aggregate_type_(aggregate_type)
134 virtual ~LinearProbingAggregateHashTable() {}
136 RC get(
int key, V &value);
138 RC iter_get(
int pos,
int &key, V &value);
142 int capacity() {
return capacity_; }
143 int size() {
return size_; }
153 void add_batch(
int *input_keys, V *input_values,
int len);
155 void aggregate(V *value, V value_to_aggregate);
159 void resize_if_need();
162 static const int EMPTY_KEY;
163 static const int DEFAULT_CAPACITY;
169 AggregateExpr::Type aggregate_type_;
Definition: expression.h:474
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:68
RC next(Chunk &chunk) override
Definition: aggregate_hash_table.cpp:27
Definition: aggregate_hash_table.h:53
StandardHashTable aggr_values_
group by values -> aggregate values
Definition: aggregate_hash_table.h:99
RC add_chunk(Chunk &groups_chunk, Chunk &aggrs_chunk) override
将 groups_chunk 和 aggrs_chunk 写入到哈希表中。哈希表中记录了聚合结果。
Definition: aggregate_hash_table.cpp:15
Definition: aggregate_hash_table.h:61
Definition: aggregate_hash_table.h:56