Skip to content

Commit

Permalink
fix vector print (#20356)
Browse files Browse the repository at this point in the history
fix vector print

Approved by: @triump2020
  • Loading branch information
XuPeng-SH authored Nov 25, 2024
1 parent bf0f867 commit 547b43a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/vm/engine/tae/common/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,18 @@ func MoVectorToString(v *vector.Vector, printN int, opts ...TypePrintOpt) string
return vec2Str(vector.MustFixedColWithTypeCheck[types.Blockid](v)[:printN], v)
}
if v.GetType().IsVarlen() {
return vec2Str(vector.InefficientMustBytesCol(v)[:printN], v, opts...)
if !v.HasNull() {
return vec2Str(vector.InefficientMustBytesCol(v)[:printN], v, opts...)
}
vs := make([][]byte, 0, printN)
for i := 0; i < printN; i++ {
if v.GetNulls().Contains(uint64(i)) {
vs = append(vs, nil)
} else {
vs = append(vs, v.GetBytesAt(i))
}
}
return vec2Str(vs, v, opts...)
}
return fmt.Sprintf("unkown type vec... %v", *v.GetType())
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/vm/engine/tae/db/test/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"errors"
"fmt"
"math"
"math/rand"
"reflect"
"sort"
Expand Down Expand Up @@ -81,6 +82,26 @@ const (
defaultGlobalCheckpointTimeout = 10 * time.Second
)

func TestPrintVector(t *testing.T) {
defer testutils.AfterTest(t)()
testutils.EnsureNoLeak(t)

mp, err := mpool.NewMPool("test", 0, mpool.NoFixed)
assert.NoError(t, err)
vec1 := vector.NewVec(types.T_uint32.ToType())
defer vec1.Free(mp)
for i := 0; i < 10; i++ {
err = vector.AppendFixed[uint32](vec1, math.MaxUint32, false, mp)
assert.NoError(t, err)
}

vec1.Reset(types.T_varchar.ToType())
err = vector.AppendBytes(vec1, nil, true, mp)
require.NoError(t, err)
s := common.MoVectorToString(vec1, 10)
t.Log(s)
}

func TestAppend1(t *testing.T) {
defer testutils.AfterTest(t)()
testutils.EnsureNoLeak(t)
Expand Down

0 comments on commit 547b43a

Please sign in to comment.