forked from Accedian/godruid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaggregations.go
187 lines (164 loc) · 4.15 KB
/
aggregations.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package godruid
import (
"encoding/json"
)
type Aggregation struct {
Type string `json:"type"`
Name string `json:"name,omitempty"`
FieldName string `json:"fieldName,omitempty"`
FieldNames []string `json:"fieldNames,omitempty"`
FnAggregate string `json:"fnAggregate,omitempty"`
FnCombine string `json:"fnCombine,omitempty"`
FnReset string `json:"fnReset,omitempty"`
ByRow bool `json:"byRow,omitempty"`
Filter *Filter `json:"filter,omitempty"`
Resolution int32 `json:"resolution,omitempty"`
NumBuckets int32 `json:"numBuckets,omitempty"`
LowerLimit string `json:"lowerLimit,omitempty"`
UpperLimit string `json:"upperLimit,omitempty"`
Aggregator *Aggregation `json:"aggregator,omitempty"`
Round bool `json:"round,omitempty"`
K int32 `json:"k,omitempty"` // druid-datasketches extension
}
func AggRawJson(rawJson string) *Aggregation {
agg := &Aggregation{}
json.Unmarshal([]byte(rawJson), agg)
return agg
}
func AggCount(name string) *Aggregation {
return &Aggregation{
Type: "count",
Name: name,
}
}
func AggLongSum(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "longSum",
Name: name,
FieldName: fieldName,
}
}
func AggDoubleSum(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "doubleSum",
Name: name,
FieldName: fieldName,
}
}
func AggMin(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "min",
Name: name,
FieldName: fieldName,
}
}
func AggMax(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "max",
Name: name,
FieldName: fieldName,
}
}
func AggDoubleMax(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "doubleMax",
Name: name,
FieldName: fieldName,
}
}
func AggDoubleMin(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "doubleMin",
Name: name,
FieldName: fieldName,
}
}
func AggLongMin(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "longMin",
Name: name,
FieldName: fieldName,
}
}
func AggLongMax(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "longMax",
Name: name,
FieldName: fieldName,
}
}
func AggDoubleMean(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "doubleMean",
Name: name,
FieldName: fieldName,
}
}
func AggFiltered(filter *Filter, aggregator *Aggregation) Aggregation {
return Aggregation{
Type: "filtered",
Filter: filter,
Aggregator: aggregator,
}
}
func AggHistoFold(name string, fieldName string, resolution int32, numBuckets int32, lowerLimit string, upperLimit string) Aggregation {
return Aggregation{
Type: "approxHistogramFold",
Name: name,
Resolution: resolution,
NumBuckets: numBuckets,
FieldName: fieldName,
LowerLimit: lowerLimit,
UpperLimit: upperLimit,
}
}
func AggJavaScript(name, fnAggregate, fnCombine, fnReset string, fieldNames []string) Aggregation {
return Aggregation{
Type: "javascript",
Name: name,
FieldNames: fieldNames,
FnAggregate: fnAggregate,
FnCombine: fnCombine,
FnReset: fnReset,
}
}
func AggCardinality(name string, fieldNames []string, byRow ...bool) Aggregation {
isByRow := false
if len(byRow) != 0 {
isByRow = byRow[0]
}
return Aggregation{
Type: "cardinality",
Name: name,
FieldNames: fieldNames,
ByRow: isByRow,
}
}
// druid-stats extension
func ExtAggVariance(name, fieldName string) *Aggregation {
return &Aggregation{
Type: "variance",
Name: name,
FieldName: fieldName,
}
}
// druid-datasketches extension
func ExtAggQuantile(name string, fieldName string, k int32) *Aggregation {
retAgg := Aggregation{
Type: "quantilesDoublesSketch",
Name: name,
FieldName: fieldName,
}
if k > 0 {
retAgg.K = k
}
return &retAgg
}
// druid-datasketches extension
func ExtAggThetaSketch(name string, fieldName string) *Aggregation {
return &Aggregation{
Type: "thetaSketch",
Name: name,
FieldName: fieldName,
}
}