Add batch block encoders

pull/10616/head
Edd Robinson 2018-09-14 16:42:29 +01:00
parent ab68204683
commit 5074b834cd
2 changed files with 138 additions and 0 deletions

View File

@ -455,6 +455,29 @@ func (a FloatValues) Encode(buf []byte) ([]byte, error) {
return encodeFloatValuesBlock(buf, a)
}
func EncodeFloatArrayBlock(a *tsdb.FloatArray, b []byte) ([]byte, error) {
if a.Len() == 0 {
return nil, nil
}
// TODO(edd): These need to be pooled.
var vb []byte
var tb []byte
var err error
if vb, err = FloatArrayEncodeAll(a.Values, vb); err != nil {
return nil, err
}
if tb, err = TimeArrayEncodeAll(a.Timestamps, tb); err != nil {
return nil, err
}
// Prepend the first timestamp of the block in the first 8 bytes and the block
// in the next byte, followed by the block
return packBlock(b, BlockFloat64, tb, vb), nil
}
func encodeFloatValuesBlock(buf []byte, values []FloatValue) ([]byte, error) {
if len(values) == 0 {
return nil, nil
@ -725,6 +748,29 @@ func (a IntegerValues) Encode(buf []byte) ([]byte, error) {
return encodeIntegerValuesBlock(buf, a)
}
func EncodeIntegerArrayBlock(a *tsdb.IntegerArray, b []byte) ([]byte, error) {
if a.Len() == 0 {
return nil, nil
}
// TODO(edd): These need to be pooled.
var vb []byte
var tb []byte
var err error
if vb, err = IntegerArrayEncodeAll(a.Values, vb); err != nil {
return nil, err
}
if tb, err = TimeArrayEncodeAll(a.Timestamps, tb); err != nil {
return nil, err
}
// Prepend the first timestamp of the block in the first 8 bytes and the block
// in the next byte, followed by the block
return packBlock(b, BlockInteger, tb, vb), nil
}
func encodeIntegerValuesBlock(buf []byte, values []IntegerValue) ([]byte, error) {
if len(values) == 0 {
return nil, nil
@ -995,6 +1041,29 @@ func (a UnsignedValues) Encode(buf []byte) ([]byte, error) {
return encodeUnsignedValuesBlock(buf, a)
}
func EncodeUnsignedArrayBlock(a *tsdb.UnsignedArray, b []byte) ([]byte, error) {
if a.Len() == 0 {
return nil, nil
}
// TODO(edd): These need to be pooled.
var vb []byte
var tb []byte
var err error
if vb, err = UnsignedArrayEncodeAll(a.Values, vb); err != nil {
return nil, err
}
if tb, err = TimeArrayEncodeAll(a.Timestamps, tb); err != nil {
return nil, err
}
// Prepend the first timestamp of the block in the first 8 bytes and the block
// in the next byte, followed by the block
return packBlock(b, BlockUnsigned, tb, vb), nil
}
func encodeUnsignedValuesBlock(buf []byte, values []UnsignedValue) ([]byte, error) {
if len(values) == 0 {
return nil, nil
@ -1265,6 +1334,29 @@ func (a StringValues) Encode(buf []byte) ([]byte, error) {
return encodeStringValuesBlock(buf, a)
}
func EncodeStringArrayBlock(a *tsdb.StringArray, b []byte) ([]byte, error) {
if a.Len() == 0 {
return nil, nil
}
// TODO(edd): These need to be pooled.
var vb []byte
var tb []byte
var err error
if vb, err = StringArrayEncodeAll(a.Values, vb); err != nil {
return nil, err
}
if tb, err = TimeArrayEncodeAll(a.Timestamps, tb); err != nil {
return nil, err
}
// Prepend the first timestamp of the block in the first 8 bytes and the block
// in the next byte, followed by the block
return packBlock(b, BlockString, tb, vb), nil
}
func encodeStringValuesBlock(buf []byte, values []StringValue) ([]byte, error) {
if len(values) == 0 {
return nil, nil
@ -1535,6 +1627,29 @@ func (a BooleanValues) Encode(buf []byte) ([]byte, error) {
return encodeBooleanValuesBlock(buf, a)
}
func EncodeBooleanArrayBlock(a *tsdb.BooleanArray, b []byte) ([]byte, error) {
if a.Len() == 0 {
return nil, nil
}
// TODO(edd): These need to be pooled.
var vb []byte
var tb []byte
var err error
if vb, err = BooleanArrayEncodeAll(a.Values, vb); err != nil {
return nil, err
}
if tb, err = TimeArrayEncodeAll(a.Timestamps, tb); err != nil {
return nil, err
}
// Prepend the first timestamp of the block in the first 8 bytes and the block
// in the next byte, followed by the block
return packBlock(b, BlockBoolean, tb, vb), nil
}
func encodeBooleanValuesBlock(buf []byte, values []BooleanValue) ([]byte, error) {
if len(values) == 0 {
return nil, nil

View File

@ -238,6 +238,29 @@ func (a {{.Name}}Values) Encode(buf []byte) ([]byte, error) {
return encode{{.Name}}ValuesBlock(buf, a)
}
func Encode{{ .Name }}ArrayBlock(a *tsdb.{{ .Name }}Array, b []byte) ([]byte, error) {
if a.Len() == 0 {
return nil, nil
}
// TODO(edd): These need to be pooled.
var vb []byte
var tb []byte
var err error
if vb, err = {{ .Name }}ArrayEncodeAll(a.Values, vb); err != nil {
return nil, err
}
if tb, err = TimeArrayEncodeAll(a.Timestamps, tb); err != nil {
return nil, err
}
// Prepend the first timestamp of the block in the first 8 bytes and the block
// in the next byte, followed by the block
return packBlock(b, {{ .Type }}, tb, vb), nil
}
func encode{{ .Name }}ValuesBlock(buf []byte, values []{{.Name}}Value) ([]byte, error) {
if len(values) == 0 {
return nil, nil