17
17
package execution
18
18
19
19
import (
20
- "runtime"
21
20
"sort"
22
21
23
22
"github.com/efficientgo/core/errors"
@@ -72,6 +71,8 @@ func newOperator(expr parser.Expr, storage *engstore.SelectorPool, opts *query.O
72
71
return newUnaryExpression (e , storage , opts , hints )
73
72
case * parser.StepInvariantExpr :
74
73
return newStepInvariantExpression (e , storage , opts , hints )
74
+ case logicalplan.Coalesce :
75
+ return newCoalesce (e , storage , opts , hints )
75
76
case logicalplan.Deduplicate :
76
77
return newDeduplication (e , storage , opts , hints )
77
78
case logicalplan.RemoteExecution :
@@ -94,21 +95,10 @@ func newVectorSelector(e *logicalplan.VectorSelector, storage *engstore.Selector
94
95
batchsize := e .BatchSize
95
96
selector := storage .GetFilteredSelector (start , end , opts .Step .Milliseconds (), e .LabelMatchers , e .Filters , hints )
96
97
97
- numShards := runtime .GOMAXPROCS (0 ) / 2
98
- if numShards < 1 {
99
- numShards = 1
100
- }
101
-
102
- operators := make ([]model.VectorOperator , 0 , numShards )
103
- for i := 0 ; i < numShards ; i ++ {
104
- operator := exchange .NewConcurrent (
105
- scan .NewVectorSelector (
106
- model .NewVectorPool (opts .StepsBatch ), selector , opts , offset , hints , batchsize , i , numShards ),
107
- 2 )
108
- operators = append (operators , operator )
109
- }
98
+ shard := e .Shard
99
+ numShards := e .NumShards
110
100
111
- return exchange . NewCoalesce (model .NewVectorPool (opts .StepsBatch ), opts , batchsize * int64 ( numShards ), operators ... ), nil
101
+ return scan . NewVectorSelector (model .NewVectorPool (opts .StepsBatch ), selector , opts , offset , hints , batchsize , shard , numShards ), nil
112
102
}
113
103
114
104
func newCall (e * parser.Call , storage * engstore.SelectorPool , opts * query.Options , hints storage.SelectHints ) (model.VectorOperator , error ) {
@@ -231,10 +221,6 @@ func newRangeVectorFunction(e *parser.Call, t *logicalplan.MatrixSelector, stora
231
221
hints .Range = milliSecondRange
232
222
filter := storage .GetFilteredSelector (start , end , opts .Step .Milliseconds (), vs .LabelMatchers , filters , hints )
233
223
234
- numShards := runtime .GOMAXPROCS (0 ) / 2
235
- if numShards < 1 {
236
- numShards = 1
237
- }
238
224
var arg float64
239
225
if e .Func .Name == "quantile_over_time" {
240
226
constVal , err := unwrapConstVal (e .Args [0 ])
@@ -243,28 +229,21 @@ func newRangeVectorFunction(e *parser.Call, t *logicalplan.MatrixSelector, stora
243
229
}
244
230
arg = constVal
245
231
}
246
-
247
- operators := make ([]model.VectorOperator , 0 , numShards )
248
- for i := 0 ; i < numShards ; i ++ {
249
- operator , err := scan .NewMatrixSelector (
250
- model .NewVectorPool (opts .StepsBatch ),
251
- filter ,
252
- e .Func .Name ,
253
- arg ,
254
- opts ,
255
- t .Range ,
256
- vs .Offset ,
257
- batchSize ,
258
- i ,
259
- numShards ,
260
- )
261
- if err != nil {
262
- return nil , err
263
- }
264
- operators = append (operators , exchange .NewConcurrent (operator , 2 ))
265
- }
266
-
267
- return exchange .NewCoalesce (model .NewVectorPool (opts .StepsBatch ), opts , batchSize * int64 (numShards ), operators ... ), nil
232
+ shard := t .Shard
233
+ numShards := t .NumShards
234
+
235
+ return scan .NewMatrixSelector (
236
+ model .NewVectorPool (opts .StepsBatch ),
237
+ filter ,
238
+ e .Func .Name ,
239
+ arg ,
240
+ opts ,
241
+ t .Range ,
242
+ vs .Offset ,
243
+ batchSize ,
244
+ shard ,
245
+ numShards ,
246
+ )
268
247
}
269
248
270
249
func newSubqueryFunction (e * parser.Call , t * parser.SubqueryExpr , storage * engstore.SelectorPool , opts * query.Options , hints storage.SelectHints ) (model.VectorOperator , error ) {
@@ -407,6 +386,18 @@ func newStepInvariantExpression(e *parser.StepInvariantExpr, storage *engstore.S
407
386
return step_invariant .NewStepInvariantOperator (model .NewVectorPoolWithSize (opts .StepsBatch , 1 ), next , e .Expr , opts )
408
387
}
409
388
389
+ func newCoalesce (e logicalplan.Coalesce , storage * engstore.SelectorPool , opts * query.Options , hints storage.SelectHints ) (model.VectorOperator , error ) {
390
+ operators := make ([]model.VectorOperator , len (e .Exprs ))
391
+ for i , expr := range e .Exprs {
392
+ operator , err := newOperator (expr , storage , opts , hints )
393
+ if err != nil {
394
+ return nil , err
395
+ }
396
+ operators [i ] = exchange .NewConcurrent (operator , 2 )
397
+ }
398
+ return exchange .NewCoalesce (model .NewVectorPool (opts .StepsBatch ), opts , 0 , operators ... ), nil
399
+ }
400
+
410
401
func newDeduplication (e logicalplan.Deduplicate , storage * engstore.SelectorPool , opts * query.Options , hints storage.SelectHints ) (model.VectorOperator , error ) {
411
402
// The Deduplicate operator will deduplicate samples using a last-sample-wins strategy.
412
403
// Sorting engines by MaxT ensures that samples produced due to
@@ -424,6 +415,7 @@ func newDeduplication(e logicalplan.Deduplicate, storage *engstore.SelectorPool,
424
415
}
425
416
operators [i ] = operator
426
417
}
418
+ // We dont need to use logical coalesce here since it was already pushed back above remote evaluation here
427
419
coalesce := exchange .NewCoalesce (model .NewVectorPool (opts .StepsBatch ), opts , 0 , operators ... )
428
420
dedup := exchange .NewDedupOperator (model .NewVectorPool (opts .StepsBatch ), coalesce )
429
421
return exchange .NewConcurrent (dedup , 2 ), nil
0 commit comments