forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udf.go
48 lines (43 loc) · 1.08 KB
/
udf.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
package tick
import (
"time"
"github.com/influxdata/kapacitor/pipeline"
"github.com/influxdata/kapacitor/tick/ast"
"github.com/influxdata/kapacitor/udf/agent"
)
// UDFNode converts the UDF pipeline node into the TICKScript AST
type UDFNode struct {
Function
}
// NewUDF creates a UDF function builder
func NewUDF(parents []ast.Node) *UDFNode {
return &UDFNode{
Function{
Parents: parents,
},
}
}
// Build creates a UDF ast.Node
func (n *UDFNode) Build(u *pipeline.UDFNode) (ast.Node, error) {
n.At(u.UDFName)
for _, o := range u.Options {
args := []interface{}{}
for _, v := range o.Values {
switch v.Type {
case agent.ValueType_BOOL:
args = append(args, v.GetBoolValue())
case agent.ValueType_INT:
args = append(args, v.GetIntValue())
case agent.ValueType_DOUBLE:
args = append(args, v.GetDoubleValue())
case agent.ValueType_STRING:
args = append(args, v.GetStringValue())
case agent.ValueType_DURATION:
dur := time.Duration(v.GetDurationValue())
args = append(args, dur)
}
}
n.Dot(o.Name, args...)
}
return n.prev, n.err
}