github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/query/block/options.go (about) 1 // Copyright (c) 2019 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 block 22 23 import xtime "github.com/m3db/m3/src/x/time" 24 25 var ( 26 defaultTimeTransform = func(t xtime.UnixNano) xtime.UnixNano { return t } 27 defaultValueTransform = func(v float64) float64 { return v } 28 defaultMetaTransform = func(m Metadata) Metadata { return m } 29 defaultSeriesMetaTransform = func(m []SeriesMeta) []SeriesMeta { return m } 30 ) 31 32 type lazyOpts struct { 33 timeTransform TimeTransform 34 valueTransform ValueTransform 35 metaTransform MetaTransform 36 seriesMetaTransform SeriesMetaTransform 37 } 38 39 // NewLazyOptions creates LazyOpts with default values. 40 func NewLazyOptions() LazyOptions { 41 return &lazyOpts{ 42 timeTransform: defaultTimeTransform, 43 valueTransform: defaultValueTransform, 44 metaTransform: defaultMetaTransform, 45 seriesMetaTransform: defaultSeriesMetaTransform, 46 } 47 } 48 49 func (o *lazyOpts) SetTimeTransform(t TimeTransform) LazyOptions { 50 opts := *o 51 opts.timeTransform = t 52 return &opts 53 } 54 55 func (o *lazyOpts) TimeTransform() TimeTransform { 56 return o.timeTransform 57 } 58 59 func (o *lazyOpts) SetValueTransform(t ValueTransform) LazyOptions { 60 opts := *o 61 opts.valueTransform = t 62 return &opts 63 } 64 65 func (o *lazyOpts) ValueTransform() ValueTransform { 66 return o.valueTransform 67 } 68 69 func (o *lazyOpts) SetMetaTransform(t MetaTransform) LazyOptions { 70 opts := *o 71 opts.metaTransform = t 72 return &opts 73 } 74 75 func (o *lazyOpts) MetaTransform() MetaTransform { 76 return o.metaTransform 77 } 78 79 func (o *lazyOpts) SetSeriesMetaTransform(t SeriesMetaTransform) LazyOptions { 80 opts := *o 81 opts.seriesMetaTransform = t 82 return &opts 83 } 84 85 func (o *lazyOpts) SeriesMetaTransform() SeriesMetaTransform { 86 return o.seriesMetaTransform 87 }