github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/query/storage/m3/encoded_step_iterator.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package m3 22 23 import ( 24 "github.com/m3db/m3/src/query/block" 25 "github.com/m3db/m3/src/query/storage/m3/consolidators" 26 ) 27 28 type encodedStepIter struct { 29 collectors []*consolidators.StepLookbackConsolidator 30 encodedStepIterWithCollector 31 values []float64 32 } 33 34 func (b *encodedBlock) StepIter() ( 35 block.StepIter, 36 error, 37 ) { 38 var ( 39 cs = b.consolidation 40 iters = b.seriesBlockIterators 41 lookback = b.options.LookbackDuration() 42 43 collectors = make([]*consolidators.StepLookbackConsolidator, len(iters)) 44 seriesCollectors = make([]consolidators.StepCollector, len(iters)) 45 ) 46 47 for i := range iters { 48 collectors[i] = consolidators.NewStepLookbackConsolidator( 49 lookback, 50 cs.bounds.StepSize, 51 cs.currentTime, 52 cs.consolidationFn, 53 ) 54 } 55 56 for i := range collectors { 57 seriesCollectors[i] = collectors[i] 58 } 59 60 iter := &encodedStepIter{ 61 collectors: collectors, 62 values: make([]float64, 0, len(iters)), 63 encodedStepIterWithCollector: encodedStepIterWithCollector{ 64 lastBlock: b.lastBlock, 65 66 stepTime: cs.currentTime, 67 blockEnd: b.meta.Bounds.End(), 68 meta: b.meta, 69 seriesMeta: b.seriesMetas, 70 71 seriesPeek: make([]peekValue, len(iters)), 72 seriesIters: iters, 73 seriesCollectors: seriesCollectors, 74 75 workerPool: b.options.ReadWorkerPool(), 76 }, 77 } 78 79 iter.encodedStepIterWithCollector.updateFn = iter.update 80 return iter, nil 81 } 82 83 func (it *encodedStepIter) update() { 84 it.values = it.values[:0] 85 for _, consolidator := range it.collectors { 86 it.values = append(it.values, consolidator.ConsolidateAndMoveToNext()) 87 } 88 } 89 90 func (it *encodedStepIter) Current() block.Step { 91 return block.NewColStep( 92 it.stepTime, 93 it.values, 94 ) 95 }