-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostaggregation.go
92 lines (80 loc) · 3.14 KB
/
postaggregation.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
package godruid
type PostAggregationType string
type GreatestLeastFunctionName string
type ArithemeticFunction string
type ThetaFunction string
var (
// PostAggregationType
ArithmeticPostAggregation PostAggregationType = "arithmetic"
FieldAccessPostAggregation PostAggregationType = "fieldAccess"
FinalizingFieldAccessPostAggregation PostAggregationType = "finalizingFieldAccess"
ConstantPostAggregation PostAggregationType = "constant"
HyperUniqueAggregation PostAggregationType = "hyperUniqueCardinality"
ThetaSketchEstimatePostAggregation PostAggregationType = "thetaSketchEstimate"
ThetaSketchSetOpPostAggregation PostAggregationType = "thetaSketchSetOp"
// GreatestLeastFunctionName
DoubleGreatest GreatestLeastFunctionName = "doubleGreatest"
LongGreatest GreatestLeastFunctionName = "longGreatest"
DoubleLeast GreatestLeastFunctionName = "doubleLeast"
LongLeast GreatestLeastFunctionName = "longLeast"
// ArithemeticFunction
PlusFunction ArithemeticFunction = "+"
MinusFunction ArithemeticFunction = "-"
MultiplyFunction ArithemeticFunction = "*"
DivideFunction ArithemeticFunction = "/"
QuotientFunction ArithemeticFunction = "quotient"
// ThetaFunction
IntersectTheta ThetaFunction = "INTERSECT"
UnionTheta ThetaFunction = "UNION"
NotTheta ThetaFunction = "NOT"
)
type PostAggregation struct {
Type PostAggregationType `json:"type"`
Name string `json:"name,omitempty"`
Fields []*PostAggregation `json:"fields,omitempty"`
Field *PostAggregation `json:"field,omitempty"`
FieldNames []string `json:"fieldNames,omitempty"`
FieldName string `json:"fieldName,omitempty"` // ffs druid
Fn ArithemeticFunction `json:"fn,omitempty"`
Func ThetaFunction `json:"func,omitempty"` // ffs again
Function string `json:"function,omitempty"`
}
func (p *PostAggregation) AddChildren(postAggs ...*PostAggregation) {
p.Fields = append(p.Fields, postAggs...)
}
func NewArithmeticPostAggregation(fn ArithemeticFunction, name string) *PostAggregation {
return &PostAggregation{
Type: ArithmeticPostAggregation,
Fn: fn,
Name: name,
}
}
func NewFieldAccessPostAggregation(fieldName string) *PostAggregation {
return &PostAggregation{
Type: FieldAccessPostAggregation,
FieldName: fieldName,
}
}
func NewHyperUniquePostAggregator(fieldName string) *PostAggregation {
return &PostAggregation{
Type: HyperUniqueAggregation,
FieldName: fieldName,
}
}
func NewGreatestLeastPostAggregation(functionName GreatestLeastFunctionName, name string, fieldNames []string) *PostAggregation {
return &PostAggregation{
Type: PostAggregationType((string)(functionName)),
}
}
func NewThetaSketchEstimatePostAggregator(metricName, outputName string, fn ThetaFunction, fields ...*PostAggregation) *PostAggregation {
return &PostAggregation{
Type: ThetaSketchEstimatePostAggregation,
Name: outputName,
Field: &PostAggregation{
Type: ThetaSketchSetOpPostAggregation,
Func: fn,
Name: outputName + ".sketch", // TODO: Not sure how other do this
Fields: fields,
},
}
}