forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flatten.go
87 lines (77 loc) · 2.21 KB
/
flatten.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
package pipeline
import "time"
const (
defaultFlattenDelimiter = "."
)
// Flatten a set of points on specific dimensions.
// For example given two points:
//
// m,host=A,port=80 bytes=3512
// m,host=A,port=443 bytes=6723
//
// Flattening the points on `port` would result in a single point:
//
// m,host=A 80.bytes=3512,443.bytes=6723
//
// Example:
// |flatten()
// .on('port')
//
// If flattening on multiple dimensions the order is preserved:
//
// m,host=A,port=80 bytes=3512
// m,host=A,port=443 bytes=6723
// m,host=B,port=443 bytes=7243
//
// Flattening the points on `host` and `port` would result in a single point:
//
// m A.80.bytes=3512,A.443.bytes=6723,B.443.bytes=7243
//
// Example:
// |flatten()
// .on('host', 'port')
//
//
// Since flattening points creates dynamically named fields in general it is expected
// that the resultant data is passed to a UDF or similar for custom processing.
type FlattenNode struct {
chainnode
// The dimensions on which to join
// tick:ignore
Dimensions []string `tick:"On"`
// The delimiter between field name parts
Delimiter string
// The maximum duration of time that two incoming points
// can be apart and still be considered to be equal in time.
// The joined data point's time will be rounded to the nearest
// multiple of the tolerance duration.
Tolerance time.Duration
// DropOriginalFieldNameFlag indicates whether the original field name should
// be included in the final field name.
//tick:ignore
DropOriginalFieldNameFlag bool `tick:"DropOriginalFieldName"`
}
func newFlattenNode(e EdgeType) *FlattenNode {
f := &FlattenNode{
chainnode: newBasicChainNode("flatten", e, e),
Delimiter: defaultFlattenDelimiter,
}
return f
}
// Specify the dimensions on which to flatten the points.
// tick:property
func (f *FlattenNode) On(dims ...string) *FlattenNode {
f.Dimensions = dims
return f
}
// DropOriginalFieldName indicates whether the original field name should
// be dropped when constructing the final field name.
// tick:property
func (f *FlattenNode) DropOriginalFieldName(drop ...bool) *FlattenNode {
if len(drop) == 1 {
f.DropOriginalFieldNameFlag = drop[0]
} else {
f.DropOriginalFieldNameFlag = true
}
return f
}