feat(gen): Add Copy(tsdb.<type>Array) method to Values

This allows data generators to produce tsdb arrays, which are
useful for testing
pull/14674/head
Stuart Carnie 2019-08-16 10:33:41 -07:00
parent 2710fac45f
commit 0054562014
No known key found for this signature in database
GPG Key ID: 848D9C9718D78B4F
2 changed files with 54 additions and 0 deletions

View File

@ -11,6 +11,10 @@ import (
"github.com/influxdata/influxdb/tsdb/tsm1"
)
type FloatValues interface {
Copy(*tsdb.FloatArray)
}
type floatArray struct {
tsdb.FloatArray
}
@ -28,6 +32,15 @@ func (a *floatArray) Encode(b []byte) ([]byte, error) {
return tsm1.EncodeFloatArrayBlock(&a.FloatArray, b)
}
func (a *floatArray) Copy(dst *tsdb.FloatArray) {
dst.Timestamps = append(dst.Timestamps[:0], a.Timestamps...)
dst.Values = append(dst.Values[:0], a.Values...)
}
type IntegerValues interface {
Copy(*tsdb.IntegerArray)
}
type integerArray struct {
tsdb.IntegerArray
}
@ -45,6 +58,15 @@ func (a *integerArray) Encode(b []byte) ([]byte, error) {
return tsm1.EncodeIntegerArrayBlock(&a.IntegerArray, b)
}
func (a *integerArray) Copy(dst *tsdb.IntegerArray) {
dst.Timestamps = append(dst.Timestamps[:0], a.Timestamps...)
dst.Values = append(dst.Values[:0], a.Values...)
}
type UnsignedValues interface {
Copy(*tsdb.UnsignedArray)
}
type unsignedArray struct {
tsdb.UnsignedArray
}
@ -62,6 +84,15 @@ func (a *unsignedArray) Encode(b []byte) ([]byte, error) {
return tsm1.EncodeUnsignedArrayBlock(&a.UnsignedArray, b)
}
func (a *unsignedArray) Copy(dst *tsdb.UnsignedArray) {
dst.Timestamps = append(dst.Timestamps[:0], a.Timestamps...)
dst.Values = append(dst.Values[:0], a.Values...)
}
type StringValues interface {
Copy(*tsdb.StringArray)
}
type stringArray struct {
tsdb.StringArray
}
@ -79,6 +110,15 @@ func (a *stringArray) Encode(b []byte) ([]byte, error) {
return tsm1.EncodeStringArrayBlock(&a.StringArray, b)
}
func (a *stringArray) Copy(dst *tsdb.StringArray) {
dst.Timestamps = append(dst.Timestamps[:0], a.Timestamps...)
dst.Values = append(dst.Values[:0], a.Values...)
}
type BooleanValues interface {
Copy(*tsdb.BooleanArray)
}
type booleanArray struct {
tsdb.BooleanArray
}
@ -95,3 +135,8 @@ func newBooleanArrayLen(sz int) *booleanArray {
func (a *booleanArray) Encode(b []byte) ([]byte, error) {
return tsm1.EncodeBooleanArrayBlock(&a.BooleanArray, b)
}
func (a *booleanArray) Copy(dst *tsdb.BooleanArray) {
dst.Timestamps = append(dst.Timestamps[:0], a.Timestamps...)
dst.Values = append(dst.Values[:0], a.Values...)
}

View File

@ -8,6 +8,10 @@ import (
{{range .}}
{{ $typename := print .name "Array" }}
{{ $tsdbname := print .Name "Array" }}
type {{.Name}}Values interface {
Copy(*tsdb.{{$tsdbname}})
}
type {{$typename}} struct {
tsdb.{{$tsdbname}}
}
@ -24,4 +28,9 @@ func new{{$tsdbname}}Len(sz int) *{{$typename}} {
func (a *{{$typename}}) Encode(b []byte) ([]byte, error) {
return tsm1.Encode{{$tsdbname}}Block(&a.{{$tsdbname}}, b)
}
func (a *{{$typename}}) Copy(dst *tsdb.{{$tsdbname}}) {
dst.Timestamps = append(dst.Timestamps[:0], a.Timestamps...)
dst.Values = append(dst.Values[:0], a.Values...)
}
{{end}}