forked from shunfei/godruid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregations.go
85 lines (75 loc) · 1.77 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
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"`
}
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 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,
}
}