-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
stats_sum_len.go
88 lines (76 loc) · 1.87 KB
/
stats_sum_len.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package logstorage
import (
"strconv"
"unsafe"
)
type statsSumLen struct {
fields []string
}
func (ss *statsSumLen) String() string {
return "sum_len(" + statsFuncFieldsToString(ss.fields) + ")"
}
func (ss *statsSumLen) updateNeededFields(neededFields fieldsSet) {
updateNeededFieldsForStatsFunc(neededFields, ss.fields)
}
func (ss *statsSumLen) newStatsProcessor() (statsProcessor, int) {
ssp := &statsSumLenProcessor{
ss: ss,
sumLen: 0,
}
return ssp, int(unsafe.Sizeof(*ssp))
}
type statsSumLenProcessor struct {
ss *statsSumLen
sumLen uint64
}
func (ssp *statsSumLenProcessor) updateStatsForAllRows(br *blockResult) int {
fields := ssp.ss.fields
if len(fields) == 0 {
// Sum all the columns
for _, c := range br.getColumns() {
ssp.sumLen += c.sumLenValues(br)
}
} else {
// Sum the requested columns
for _, field := range fields {
c := br.getColumnByName(field)
ssp.sumLen += c.sumLenValues(br)
}
}
return 0
}
func (ssp *statsSumLenProcessor) updateStatsForRow(br *blockResult, rowIdx int) int {
fields := ssp.ss.fields
if len(fields) == 0 {
// Sum all the fields for the given row
for _, c := range br.getColumns() {
v := c.getValueAtRow(br, rowIdx)
ssp.sumLen += uint64(len(v))
}
} else {
// Sum only the given fields for the given row
for _, field := range fields {
c := br.getColumnByName(field)
v := c.getValueAtRow(br, rowIdx)
ssp.sumLen += uint64(len(v))
}
}
return 0
}
func (ssp *statsSumLenProcessor) mergeState(sfp statsProcessor) {
src := sfp.(*statsSumLenProcessor)
ssp.sumLen += src.sumLen
}
func (ssp *statsSumLenProcessor) finalizeStats() string {
return strconv.FormatUint(ssp.sumLen, 10)
}
func parseStatsSumLen(lex *lexer) (*statsSumLen, error) {
fields, err := parseStatsFuncFields(lex, "sum_len")
if err != nil {
return nil, err
}
ss := &statsSumLen{
fields: fields,
}
return ss, nil
}