forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
union.go
60 lines (55 loc) · 1.17 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
package kapacitor
import (
"github.com/influxdb/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) (*UnionNode, error) {
un := &UnionNode{
u: n,
node: node{Node: n, et: et},
}
un.node.runF = un.runUnion
return un, nil
}
func (u *UnionNode) runUnion() error {
errors := make(chan error, len(u.ins))
for _, in := range u.ins {
go func(e *Edge) {
switch u.Wants() {
case pipeline.StreamEdge:
for p := e.NextPoint(); p != nil; p = e.NextPoint() {
for _, out := range u.outs {
err := out.CollectPoint(p)
if err != nil {
errors <- err
return
}
}
}
case pipeline.BatchEdge:
for b := e.NextBatch(); b != nil; b = e.NextBatch() {
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
}