forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
influx.go
43 lines (38 loc) · 988 Bytes
/
influx.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
package tick
import (
"strings"
"github.com/influxdata/kapacitor/pipeline"
"github.com/influxdata/kapacitor/tick/ast"
)
// InfluxQLNode converts the InfluxQLNode pipeline node into the TICKScript AST
type InfluxQLNode struct {
Function
}
// NewInfluxQL creates a InfluxQLNode function builder
func NewInfluxQL(parents []ast.Node) *InfluxQLNode {
return &InfluxQLNode{
Function{
Parents: parents,
},
}
}
// Build creates a InfluxQLNode ast.Node
func (n *InfluxQLNode) Build(q *pipeline.InfluxQLNode) (ast.Node, error) {
args := []interface{}{}
if strings.ToLower(q.Method) == "bottom" || strings.ToLower(q.Method) == "top" {
if len(q.Args) > 0 {
args = append(args, q.Args[0])
args = append(args, q.Field)
args = append(args, q.Args[1:]...)
}
} else {
if q.Field != "" {
args = append(args, q.Field)
}
args = append(args, q.Args...)
}
n.Pipe(q.Method, args...).
Dot("as", q.As).
DotIf("usePointTimes", q.PointTimes)
return n.prev, n.err
}