forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_reduce.go
83 lines (75 loc) · 2.03 KB
/
map_reduce.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
package pipeline
// tick:ignore
type MapReduceInfo struct {
Map interface{}
Reduce interface{}
Edge EdgeType
}
// Performs a map operation on the data stream.
// In the map-reduce framework it is assumed that
// several different partitions of the data can be
// 'mapped' in parallel while only one 'reduce' operation
// will process all of the data stream.
//
// Example:
// stream
// .window()
// .period(10s)
// .every(10s)
// // Sum the values for each 10s window of data.
// .mapReduce(influxql.sum('value'))
// ...
type MapNode struct {
chainnode
// The map function
// tick:ignore
Map interface{}
}
func newMapNode(wants EdgeType, i interface{}) *MapNode {
return &MapNode{
chainnode: newBasicChainNode("map", wants, ReduceEdge),
Map: i,
}
}
// Performs a reduce operation on the data stream.
// In the map-reduce framework it is assumed that
// several different partitions of the data can be
// 'mapped' in parallel while only one 'reduce' operation
// will process all of the data stream.
//
// Example:
// stream
// .window()
// .period(10s)
// .every(10s)
// // Sum the values for each 10s window of data.
// .mapReduce(influxql.sum('value'))
// ...
type ReduceNode struct {
chainnode
//The reduce function
// tick:ignore
Reduce interface{}
// Whether to use the max time or the
// time of the selected point
// tick:ignore
PointTimes bool
// The name of the field, defaults to the name of
// MR function used (i.e. influxql.mean -> 'mean')
As string
}
func newReduceNode(i interface{}, et EdgeType) *ReduceNode {
return &ReduceNode{
chainnode: newBasicChainNode("reduce", ReduceEdge, et),
Reduce: i,
}
}
// Use the time of the selected point instead of the time of the batch.
//
// Only applies to selector MR functions like first, last, top, bottom, etc.
// Aggregation functions always use the batch time.
// tick:property
func (r *ReduceNode) UsePointTimes() *ReduceNode {
r.PointTimes = true
return r
}