-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
operators.go
186 lines (151 loc) · 4.59 KB
/
operators.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package influxdb
import (
"context"
"errors"
"fmt"
"strings"
"github.com/influxdata/flux"
"github.com/influxdata/flux/execute"
"github.com/influxdata/flux/plan"
"github.com/influxdata/flux/values"
"github.com/influxdata/influxdb/services/meta"
"github.com/influxdata/influxdb/storage/reads/datatypes"
"github.com/influxdata/influxql"
)
const (
ReadRangePhysKind = "ReadRangePhysKind"
ReadGroupPhysKind = "ReadGroupPhysKind"
ReadWindowAggregatePhysKind = "ReadWindowAggregatePhysKind"
ReadTagKeysPhysKind = "ReadTagKeysPhysKind"
ReadTagValuesPhysKind = "ReadTagValuesPhysKind"
)
type ReadGroupPhysSpec struct {
plan.DefaultCost
ReadRangePhysSpec
GroupMode flux.GroupMode
GroupKeys []string
AggregateMethod string
}
func (s *ReadGroupPhysSpec) Kind() plan.ProcedureKind {
return ReadGroupPhysKind
}
func (s *ReadGroupPhysSpec) Copy() plan.ProcedureSpec {
ns := new(ReadGroupPhysSpec)
ns.ReadRangePhysSpec = *s.ReadRangePhysSpec.Copy().(*ReadRangePhysSpec)
ns.GroupMode = s.GroupMode
ns.GroupKeys = s.GroupKeys
ns.AggregateMethod = s.AggregateMethod
return ns
}
type ReadRangePhysSpec struct {
plan.DefaultCost
Bucket string
BucketID string
// Predicate is the filtering predicate for calling into storage.
// It must not be mutated.
Predicate *datatypes.Predicate
Bounds flux.Bounds
}
func (s *ReadRangePhysSpec) Kind() plan.ProcedureKind {
return ReadRangePhysKind
}
func (s *ReadRangePhysSpec) Copy() plan.ProcedureSpec {
ns := new(ReadRangePhysSpec)
ns.Bucket = s.Bucket
ns.BucketID = s.BucketID
ns.Predicate = s.Predicate
ns.Bounds = s.Bounds
return ns
}
func lookupDatabase(ctx context.Context, bucketName string, deps StorageDependencies, privilege influxql.Privilege) (string, string, error) {
var db, rp string
if i := strings.IndexByte(bucketName, '/'); i == -1 {
db = bucketName
} else {
rp = bucketName[i+1:]
db = bucketName[:i]
}
// validate and resolve db/rp
di := deps.MetaClient.Database(db)
if di == nil {
return "", "", errors.New("no database")
}
if deps.AuthEnabled {
user := meta.UserFromContext(ctx)
if user == nil {
return "", "", errors.New("no user for auth-enabled flux access")
}
if err := deps.Authorizer.AuthorizeDatabase(user, privilege, db); err != nil {
return "", "", err
}
}
if rp == "" {
rp = di.DefaultRetentionPolicy
}
if rpi := di.RetentionPolicy(rp); rpi == nil {
return "", "", errors.New("invalid retention policy")
}
return db, rp, nil
}
func (s *ReadRangePhysSpec) LookupDatabase(_ context.Context, deps StorageDependencies, a execute.Administration) (string, string, error) {
if len(s.BucketID) != 0 {
return "", "", errors.New("cannot refer to buckets by their id in 1.x")
}
return lookupDatabase(a.Context(), s.Bucket, deps, influxql.ReadPrivilege)
}
// TimeBounds implements plan.BoundsAwareProcedureSpec.
func (s *ReadRangePhysSpec) TimeBounds(predecessorBounds *plan.Bounds) *plan.Bounds {
return &plan.Bounds{
Start: values.ConvertTime(s.Bounds.Start.Time(s.Bounds.Now)),
Stop: values.ConvertTime(s.Bounds.Stop.Time(s.Bounds.Now)),
}
}
type ReadWindowAggregatePhysSpec struct {
plan.DefaultCost
ReadRangePhysSpec
WindowEvery flux.Duration
Offset flux.Duration
Aggregates []plan.ProcedureKind
CreateEmpty bool
TimeColumn string
}
func (s *ReadWindowAggregatePhysSpec) PlanDetails() string {
return fmt.Sprintf("every = %v, aggregates = %v, createEmpty = %v, timeColumn = \"%s\"", s.WindowEvery, s.Aggregates, s.CreateEmpty, s.TimeColumn)
}
func (s *ReadWindowAggregatePhysSpec) Kind() plan.ProcedureKind {
return ReadWindowAggregatePhysKind
}
func (s *ReadWindowAggregatePhysSpec) Copy() plan.ProcedureSpec {
ns := new(ReadWindowAggregatePhysSpec)
ns.ReadRangePhysSpec = *s.ReadRangePhysSpec.Copy().(*ReadRangePhysSpec)
ns.WindowEvery = s.WindowEvery
ns.Offset = s.Offset
ns.Aggregates = s.Aggregates
ns.CreateEmpty = s.CreateEmpty
ns.TimeColumn = s.TimeColumn
return ns
}
type ReadTagKeysPhysSpec struct {
ReadRangePhysSpec
}
func (s *ReadTagKeysPhysSpec) Kind() plan.ProcedureKind {
return ReadTagKeysPhysKind
}
func (s *ReadTagKeysPhysSpec) Copy() plan.ProcedureSpec {
ns := new(ReadTagKeysPhysSpec)
ns.ReadRangePhysSpec = *s.ReadRangePhysSpec.Copy().(*ReadRangePhysSpec)
return ns
}
type ReadTagValuesPhysSpec struct {
ReadRangePhysSpec
TagKey string
}
func (s *ReadTagValuesPhysSpec) Kind() plan.ProcedureKind {
return ReadTagValuesPhysKind
}
func (s *ReadTagValuesPhysSpec) Copy() plan.ProcedureSpec {
ns := new(ReadTagValuesPhysSpec)
ns.ReadRangePhysSpec = *s.ReadRangePhysSpec.Copy().(*ReadRangePhysSpec)
ns.TagKey = s.TagKey
return ns
}