@@ -19,7 +19,6 @@ package execution
19
19
import (
20
20
"runtime"
21
21
"sort"
22
- "time"
23
22
24
23
"github.com/efficientgo/core/errors"
25
24
"github.com/prometheus/prometheus/model/labels"
@@ -59,8 +58,8 @@ func newOperator(expr parser.Expr, storage *engstore.SelectorPool, opts *query.O
59
58
switch e := expr .(type ) {
60
59
case * parser.NumberLiteral :
61
60
return scan .NewNumberLiteralSelector (model .NewVectorPool (opts .StepsBatch ), opts , e .Val ), nil
62
- case * parser. VectorSelector , * logicalplan.VectorSelector :
63
- return newVectorSelector (expr , storage , opts , hints )
61
+ case * logicalplan.VectorSelector :
62
+ return newVectorSelector (e , storage , opts , hints )
64
63
case * parser.Call :
65
64
return newCall (e , storage , opts , hints )
66
65
case * parser.AggregateExpr :
@@ -82,34 +81,18 @@ func newOperator(expr parser.Expr, storage *engstore.SelectorPool, opts *query.O
82
81
case logicalplan.UserDefinedExpr :
83
82
return e .MakeExecutionOperator (model .NewVectorPool (opts .StepsBatch ), storage , opts , hints )
84
83
default :
85
- return nil , errors .Wrapf (parse .ErrNotSupportedExpr , "got: %s" , e )
84
+ return nil , errors .Wrapf (parse .ErrNotSupportedExpr , "got: %s (%T)" , e , e )
86
85
}
87
86
}
88
87
89
- func newVectorSelector (expr parser.Expr , storage * engstore.SelectorPool , opts * query.Options , hints storage.SelectHints ) (model.VectorOperator , error ) {
90
- var (
91
- batchsize int64
92
- offset time.Duration
93
- selector engstore.SeriesSelector
94
- )
95
- switch e := expr .(type ) {
96
- case * parser.VectorSelector :
97
- start , end := getTimeRangesForVectorSelector (e , opts , 0 )
98
- hints .Start = start
99
- hints .End = end
100
- offset = e .Offset
101
- batchsize = 0
102
- selector = storage .GetSelector (start , end , opts .Step .Milliseconds (), e .LabelMatchers , hints )
103
- case * logicalplan.VectorSelector :
104
- start , end := getTimeRangesForVectorSelector (e .VectorSelector , opts , 0 )
105
- hints .Start = start
106
- hints .End = end
107
- offset = e .Offset
108
- batchsize = e .BatchSize
109
- selector = storage .GetFilteredSelector (start , end , opts .Step .Milliseconds (), e .LabelMatchers , e .Filters , hints )
110
- default :
111
- return nil , errors .Wrapf (parse .ErrNotSupportedExpr , "got: %s" , e )
112
- }
88
+ func newVectorSelector (e * logicalplan.VectorSelector , storage * engstore.SelectorPool , opts * query.Options , hints storage.SelectHints ) (model.VectorOperator , error ) {
89
+ start , end := getTimeRangesForVectorSelector (e , opts , 0 )
90
+ hints .Start = start
91
+ hints .End = end
92
+
93
+ offset := e .Offset
94
+ batchsize := e .BatchSize
95
+ selector := storage .GetFilteredSelector (start , end , opts .Step .Milliseconds (), e .LabelMatchers , e .Filters , hints )
113
96
114
97
numShards := runtime .GOMAXPROCS (0 ) / 2
115
98
if numShards < 1 {
@@ -138,19 +121,13 @@ func newCall(e *parser.Call, storage *engstore.SelectorPool, opts *query.Options
138
121
}
139
122
if e .Func .Name == "timestamp" {
140
123
switch arg := e .Args [0 ].(type ) {
141
- case * logicalplan.VectorSelector , * parser. VectorSelector :
124
+ case * logicalplan.VectorSelector :
142
125
// We push down the timestamp function into the scanner through the hints.
143
- return newVectorSelector (e . Args [ 0 ] , storage , opts , hints )
126
+ return newVectorSelector (arg , storage , opts , hints )
144
127
case * parser.StepInvariantExpr :
145
128
// Step invariant expressions on vector selectors need to be unwrapped so that we
146
129
// can return the original timestamp rather than the step invariant one.
147
130
switch vs := arg .Expr .(type ) {
148
- case * parser.VectorSelector :
149
- // Prometheus weirdness.
150
- if vs .Timestamp != nil {
151
- vs .OriginalOffset = 0
152
- }
153
- return newVectorSelector (vs , storage , opts , hints )
154
131
case * logicalplan.VectorSelector :
155
132
// Prometheus weirdness.
156
133
if vs .Timestamp != nil {
@@ -175,7 +152,7 @@ func newCall(e *parser.Call, storage *engstore.SelectorPool, opts *query.Options
175
152
return nil , parse .ErrNotImplemented
176
153
}
177
154
return newSubqueryFunction (e , t , storage , opts , hints )
178
- case * parser .MatrixSelector :
155
+ case * logicalplan .MatrixSelector :
179
156
return newRangeVectorFunction (e , t , storage , opts , hints )
180
157
}
181
158
}
@@ -203,7 +180,7 @@ func newAbsentOverTimeOperator(call *parser.Call, storage *engstore.SelectorPool
203
180
Args : []parser.Expr {matrixCall },
204
181
}
205
182
return function .NewFunctionOperator (f , []model.VectorOperator {argOp }, opts .StepsBatch , opts )
206
- case * parser .MatrixSelector :
183
+ case * logicalplan .MatrixSelector :
207
184
matrixCall := & parser.Call {
208
185
Func : & parser.Function {Name : "last_over_time" },
209
186
Args : call .Args ,
@@ -221,9 +198,12 @@ func newAbsentOverTimeOperator(call *parser.Call, storage *engstore.SelectorPool
221
198
vs .LabelMatchers = append (vs .LabelMatchers , filters ... )
222
199
f := & parser.Call {
223
200
Func : & parser.Function {Name : "absent" },
224
- Args : []parser.Expr {& parser.MatrixSelector {
225
- VectorSelector : vs ,
226
- Range : arg .Range ,
201
+ Args : []parser.Expr {& logicalplan.MatrixSelector {
202
+ MatrixSelector : & parser.MatrixSelector {
203
+ VectorSelector : vs ,
204
+ Range : arg .Range ,
205
+ },
206
+ OriginalString : arg .String (),
227
207
}},
228
208
}
229
209
return function .NewFunctionOperator (f , []model.VectorOperator {argOp }, opts .StepsBatch , opts )
@@ -232,7 +212,7 @@ func newAbsentOverTimeOperator(call *parser.Call, storage *engstore.SelectorPool
232
212
}
233
213
}
234
214
235
- func newRangeVectorFunction (e * parser.Call , t * parser .MatrixSelector , storage * engstore.SelectorPool , opts * query.Options , hints storage.SelectHints ) (model.VectorOperator , error ) {
215
+ func newRangeVectorFunction (e * parser.Call , t * logicalplan .MatrixSelector , storage * engstore.SelectorPool , opts * query.Options , hints storage.SelectHints ) (model.VectorOperator , error ) {
236
216
// TODO(saswatamcode): Range vector result might need new operator
237
217
// before it can be non-nested. https://github.com/thanos-io/promql-engine/issues/39
238
218
batchSize , vs , filters , err := unpackVectorSelector (t )
@@ -466,7 +446,7 @@ func newRemoteExecution(e logicalplan.RemoteExecution, opts *query.Options, hint
466
446
}
467
447
468
448
// Copy from https://github.com/prometheus/prometheus/blob/v2.39.1/promql/engine.go#L791.
469
- func getTimeRangesForVectorSelector (n * parser .VectorSelector , opts * query.Options , evalRange int64 ) (int64 , int64 ) {
449
+ func getTimeRangesForVectorSelector (n * logicalplan .VectorSelector , opts * query.Options , evalRange int64 ) (int64 , int64 ) {
470
450
start := opts .Start .UnixMilli ()
471
451
end := opts .End .UnixMilli ()
472
452
if n .Timestamp != nil {
@@ -493,12 +473,10 @@ func unwrapConstVal(e parser.Expr) (float64, error) {
493
473
return 0 , errors .Wrap (parse .ErrNotSupportedExpr , "matrix selector argument must be a constant" )
494
474
}
495
475
496
- func unpackVectorSelector (t * parser .MatrixSelector ) (int64 , * parser .VectorSelector , []* labels.Matcher , error ) {
476
+ func unpackVectorSelector (t * logicalplan .MatrixSelector ) (int64 , * logicalplan .VectorSelector , []* labels.Matcher , error ) {
497
477
switch t := t .VectorSelector .(type ) {
498
- case * parser.VectorSelector :
499
- return 0 , t , nil , nil
500
478
case * logicalplan.VectorSelector :
501
- return t .BatchSize , t . VectorSelector , t .Filters , nil
479
+ return t .BatchSize , t , t .Filters , nil
502
480
default :
503
481
return 0 , nil , nil , parse .ErrNotSupportedExpr
504
482
}
0 commit comments