Debian Codegraph @

stress/v2/statement/template.go

raw symbols SCIP
1 package statement
2
3 // A Template contains all information to fill in templated variables in inset and query statements
4 type Template struct {
5 Tags []string
6 Function *Function
7 }
8
9 // Templates are a collection of Template
10 type Templates []*Template
11
12 // Init makes Stringers out of the Templates for quick point creation
13 func (t Templates) Init(seriesCount int) Stringers {
14 arr := make([]Stringer, len(t))
15 for i, tmp := range t {
16 if len(tmp.Tags) == 0 {
17 arr[i] = tmp.Function.NewStringer(seriesCount)
18 continue
19 }
20 arr[i] = tmp.NewTagFunc()
21 }
22 return arr
23 }
24
25 // Calculates the number of series implied by a template
26 func (t *Template) numSeries() int {
27 // If !t.Tags then tag cardinality is t.Function.Count
28 if len(t.Tags) == 0 {
29 return t.Function.Count
30 }
31 // Else tag cardinality is len(t.Tags)
32 return len(t.Tags)
33 }
34
35 // NewTagFunc returns a Stringer that loops through the given tags
36 func (t *Template) NewTagFunc() Stringer {
37 if len(t.Tags) == 0 {
38 return func() string { return "EMPTY TAGS" }
39 }
40
41 i := 0
42 return func() string {
43 s := t.Tags[i]
44 i = (i + 1) % len(t.Tags)
45 return s
46 }
47 }