MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
aggregate_state.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11#include "sql/expr/expression.h"
12#include "common/type/attr_type.h"
13template <class T>
15{
16public:
17 SumState() : value(0) {}
18 T value;
19 void update(const T *values, int size);
20 void update(const T &value) { this->value += value; }
21 template <class U>
22 U finalize()
23 {
24 return (U)value;
25 }
26};
27
28template <class T>
30{
31public:
32 CountState() : value(0) {}
33 int value;
34 void update(const T *values, int size);
35 void update(const T &value) { this->value++; }
36 template <class U>
37 U finalize()
38 {
39 return (U)value;
40 }
41};
42
43template <class T>
45{
46public:
47 AvgState() : value(0), count(0) {}
48 T value;
49 int count = 0;
50 void update(const T *values, int size);
51 void update(const T &value)
52 {
53 this->value += value;
54 this->count++;
55 }
56 template <class U>
57 U finalize()
58 {
59 return (U)((float)value / (float)count);
60 }
61};
62
63void *create_aggregate_state(AggregateExpr::Type aggr_type, AttrType attr_type);
64
65RC aggregate_state_update_by_value(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, const Value &val);
66RC aggregate_state_update_by_column(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, Column &col);
67
68RC finialize_aggregate_state(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, Column &col);
Definition: aggregate_state.h:45
A column contains multiple values in contiguous memory with a specified type.
Definition: column.h:23
Definition: aggregate_state.h:30
Definition: aggregate_state.h:15
属性的值
Definition: value.h:31