-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregation_executor.cpp
More file actions
39 lines (36 loc) · 1.24 KB
/
Copy pathaggregation_executor.cpp
File metadata and controls
39 lines (36 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "../include/aggregation_executor.h"
AggregationExecutor::AggregationExecutor(AbstractExecutor *child_executor,
AggregationType aggr_type)
: child_(child_executor), aggr_type_(aggr_type){};
void AggregationExecutor::Init() { child_->Init(); }
bool AggregationExecutor::Next(Tuple *tuple) {
int numberOfTuples = 0, totalSum = 0, maxValue1 = INT_MIN, minValue1 = INT_MAX;
while (child_->Next(tuple)) {
numberOfTuples++;
totalSum += tuple->val1;
maxValue1 = std::max(maxValue1, tuple->val1);
minValue1 = std::min(minValue1, tuple->val1);
}
if (numberOfTuples > 0) {
tuple->id = 0;
tuple->val2 = "";
switch (aggr_type_) {
case AggregationType::MIN:
tuple->val1 = minValue1;
break;
case AggregationType::SUM:
tuple->val1 = totalSum;
break;
case AggregationType::MAX:
tuple->val1 = maxValue1;
break;
case AggregationType::COUNT:
tuple->val1 = numberOfTuples;
break;
default:
break;
}
return true;
}
return false;
}