This commit is contained in:
Aliaksandr Valialkin 2024-05-11 01:10:07 +02:00
parent fb2a280077
commit 3bc01a1ad6
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
3 changed files with 19 additions and 22 deletions

View file

@ -433,7 +433,7 @@ func (b *block) InitFromBlockData(bd *blockData, sbu *stringsBlockUnmarshaler, v
if err != nil {
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)
}
}
@ -577,9 +577,7 @@ func getColumnIdxs() map[string]int {
}
func putColumnIdxs(m map[string]int) {
for k := range m {
delete(m, k)
}
clear(m)
columnIdxsPool.Put(m)
}

View file

@ -135,10 +135,10 @@ func (vd *valuesDecoder) reset() {
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.
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,
// which must be preserved until reset() call.
dstBuf := vd.buf
@ -146,6 +146,14 @@ func (vd *valuesDecoder) decodeInplace(values []string, vt valueType, dict *valu
switch vt {
case valueTypeString:
// 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:
for i, v := range values {
if len(v) != 1 {
@ -189,14 +197,14 @@ func (vd *valuesDecoder) decodeInplace(values []string, vt valueType, dict *valu
dstBuf = marshalUint64(dstBuf, n)
values[i] = bytesutil.ToUnsafeString(dstBuf[dstLen:])
}
case valueTypeDict:
dictValues := dict.values
case valueTypeFloat64:
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))
if len(v) != 8 {
return fmt.Errorf("unexpected value length for uint64; got %d; want 8", len(v))
}
values[i] = dictValues[id]
dstLen := len(dstBuf)
dstBuf = toFloat64String(dstBuf, v)
values[i] = bytesutil.ToUnsafeString(dstBuf[dstLen:])
}
case valueTypeIPv4:
for i, v := range values {
@ -216,15 +224,6 @@ func (vd *valuesDecoder) decodeInplace(values []string, vt valueType, dict *valu
dstBuf = toTimestampISO8601String(dstBuf, v)
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:
return fmt.Errorf("unknown valueType=%d", vt)
}

View file

@ -26,7 +26,7 @@ func TestValuesEncoder(t *testing.T) {
putValuesEncoder(ve)
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)
}
if len(values) == 0 {