forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
union.go
69 lines (63 loc) · 1.38 KB
/
union.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
package kapacitor
import (
"log"
"github.com/influxdata/kapacitor/pipeline"
)
type UnionNode struct {
node
u *pipeline.UnionNode
}
// Create a new UnionNode which combines all parent data streams into a single stream.
// No transformation of any kind is performed.
func newUnionNode(et *ExecutingTask, n *pipeline.UnionNode, l *log.Logger) (*UnionNode, error) {
un := &UnionNode{
u: n,
node: node{Node: n, et: et, logger: l},
}
un.node.runF = un.runUnion
return un, nil
}
func (u *UnionNode) runUnion([]byte) error {
rename := u.u.Rename
if rename == "" {
//the calling node is always the last node
rename = u.parents[len(u.parents)-1].Name()
}
errors := make(chan error, len(u.ins))
for _, in := range u.ins {
go func(e *Edge) {
switch u.Wants() {
case pipeline.StreamEdge:
for p, ok := e.NextPoint(); ok; p, ok = e.NextPoint() {
p.Name = rename
for _, out := range u.outs {
err := out.CollectPoint(p)
if err != nil {
errors <- err
return
}
}
}
case pipeline.BatchEdge:
for b, ok := e.NextBatch(); ok; b, ok = e.NextBatch() {
b.Name = rename
for _, out := range u.outs {
err := out.CollectBatch(b)
if err != nil {
errors <- err
return
}
}
}
}
errors <- nil
}(in)
}
for range u.ins {
err := <-errors
if err != nil {
return err
}
}
return nil
}