mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
wip
This commit is contained in:
parent
fb2a280077
commit
3bc01a1ad6
3 changed files with 19 additions and 22 deletions
|
@ -433,7 +433,7 @@ func (b *block) InitFromBlockData(bd *blockData, sbu *stringsBlockUnmarshaler, v
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot unmarshal column %d: %w", i, err)
|
return fmt.Errorf("cannot unmarshal column %d: %w", i, err)
|
||||||
}
|
}
|
||||||
if err = vd.decodeInplace(c.values, cd.valueType, &cd.valuesDict); err != nil {
|
if err = vd.decodeInplace(c.values, cd.valueType, cd.valuesDict.values); err != nil {
|
||||||
return fmt.Errorf("cannot decode column values: %w", err)
|
return fmt.Errorf("cannot decode column values: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -577,9 +577,7 @@ func getColumnIdxs() map[string]int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func putColumnIdxs(m map[string]int) {
|
func putColumnIdxs(m map[string]int) {
|
||||||
for k := range m {
|
clear(m)
|
||||||
delete(m, k)
|
|
||||||
}
|
|
||||||
columnIdxsPool.Put(m)
|
columnIdxsPool.Put(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,10 +135,10 @@ func (vd *valuesDecoder) reset() {
|
||||||
vd.buf = vd.buf[:0]
|
vd.buf = vd.buf[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// decodeInplace decodes values encoded with the given vt and the given dict inplace.
|
// decodeInplace decodes values encoded with the given vt and the given dictValues inplace.
|
||||||
//
|
//
|
||||||
// the decoded values remain valid until vd.reset() is called.
|
// the decoded values remain valid until vd.reset() is called.
|
||||||
func (vd *valuesDecoder) decodeInplace(values []string, vt valueType, dict *valuesDict) error {
|
func (vd *valuesDecoder) decodeInplace(values []string, vt valueType, dictValues []string) error {
|
||||||
// do not reset vd.buf, since it may contain previously decoded data,
|
// do not reset vd.buf, since it may contain previously decoded data,
|
||||||
// which must be preserved until reset() call.
|
// which must be preserved until reset() call.
|
||||||
dstBuf := vd.buf
|
dstBuf := vd.buf
|
||||||
|
@ -146,6 +146,14 @@ func (vd *valuesDecoder) decodeInplace(values []string, vt valueType, dict *valu
|
||||||
switch vt {
|
switch vt {
|
||||||
case valueTypeString:
|
case valueTypeString:
|
||||||
// nothing to do - values are already decoded.
|
// nothing to do - values are already decoded.
|
||||||
|
case valueTypeDict:
|
||||||
|
for i, v := range values {
|
||||||
|
id := int(v[0])
|
||||||
|
if id >= len(dictValues) {
|
||||||
|
return fmt.Errorf("unexpected dictionary id: %d; it must be smaller than %d", id, len(dictValues))
|
||||||
|
}
|
||||||
|
values[i] = dictValues[id]
|
||||||
|
}
|
||||||
case valueTypeUint8:
|
case valueTypeUint8:
|
||||||
for i, v := range values {
|
for i, v := range values {
|
||||||
if len(v) != 1 {
|
if len(v) != 1 {
|
||||||
|
@ -189,14 +197,14 @@ func (vd *valuesDecoder) decodeInplace(values []string, vt valueType, dict *valu
|
||||||
dstBuf = marshalUint64(dstBuf, n)
|
dstBuf = marshalUint64(dstBuf, n)
|
||||||
values[i] = bytesutil.ToUnsafeString(dstBuf[dstLen:])
|
values[i] = bytesutil.ToUnsafeString(dstBuf[dstLen:])
|
||||||
}
|
}
|
||||||
case valueTypeDict:
|
case valueTypeFloat64:
|
||||||
dictValues := dict.values
|
|
||||||
for i, v := range values {
|
for i, v := range values {
|
||||||
id := int(v[0])
|
if len(v) != 8 {
|
||||||
if id >= len(dictValues) {
|
return fmt.Errorf("unexpected value length for uint64; got %d; want 8", len(v))
|
||||||
return fmt.Errorf("unexpected dictionary id: %d; it must be smaller than %d", id, len(dictValues))
|
|
||||||
}
|
}
|
||||||
values[i] = dictValues[id]
|
dstLen := len(dstBuf)
|
||||||
|
dstBuf = toFloat64String(dstBuf, v)
|
||||||
|
values[i] = bytesutil.ToUnsafeString(dstBuf[dstLen:])
|
||||||
}
|
}
|
||||||
case valueTypeIPv4:
|
case valueTypeIPv4:
|
||||||
for i, v := range values {
|
for i, v := range values {
|
||||||
|
@ -216,15 +224,6 @@ func (vd *valuesDecoder) decodeInplace(values []string, vt valueType, dict *valu
|
||||||
dstBuf = toTimestampISO8601String(dstBuf, v)
|
dstBuf = toTimestampISO8601String(dstBuf, v)
|
||||||
values[i] = bytesutil.ToUnsafeString(dstBuf[dstLen:])
|
values[i] = bytesutil.ToUnsafeString(dstBuf[dstLen:])
|
||||||
}
|
}
|
||||||
case valueTypeFloat64:
|
|
||||||
for i, v := range values {
|
|
||||||
if len(v) != 8 {
|
|
||||||
return fmt.Errorf("unexpected value length for uint64; got %d; want 8", len(v))
|
|
||||||
}
|
|
||||||
dstLen := len(dstBuf)
|
|
||||||
dstBuf = toFloat64String(dstBuf, v)
|
|
||||||
values[i] = bytesutil.ToUnsafeString(dstBuf[dstLen:])
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown valueType=%d", vt)
|
return fmt.Errorf("unknown valueType=%d", vt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func TestValuesEncoder(t *testing.T) {
|
||||||
putValuesEncoder(ve)
|
putValuesEncoder(ve)
|
||||||
|
|
||||||
vd := getValuesDecoder()
|
vd := getValuesDecoder()
|
||||||
if err := vd.decodeInplace(encodedValues, vt, &dict); err != nil {
|
if err := vd.decodeInplace(encodedValues, vt, dict.values); err != nil {
|
||||||
t.Fatalf("unexpected error in decodeInplace(): %s", err)
|
t.Fatalf("unexpected error in decodeInplace(): %s", err)
|
||||||
}
|
}
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
|
|
Loading…
Reference in a new issue