mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-03 04:19:18 +08:00
a6f1de036b
Signed-off-by: xige-16 <xi.ge@zilliz.com>
81 lines
2.4 KiB
Go
81 lines
2.4 KiB
Go
package querynode
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/milvuspb"
|
|
)
|
|
|
|
func TestPlan_Plan(t *testing.T) {
|
|
collectionID := UniqueID(0)
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
|
|
|
dslString := "{\"bool\": { \n\"vector\": {\n \"vec\": {\n \"metric_type\": \"L2\", \n \"params\": {\n \"nprobe\": 10 \n},\n \"query\": \"$0\",\"topk\": 10 \n } \n } \n } \n }"
|
|
|
|
plan, err := createPlan(*collection, dslString)
|
|
assert.NoError(t, err)
|
|
assert.NotEqual(t, plan, nil)
|
|
topk := plan.getTopK()
|
|
assert.Equal(t, int(topk), 10)
|
|
metricType := plan.getMetricType()
|
|
assert.Equal(t, metricType, "L2")
|
|
plan.delete()
|
|
deleteCollection(collection)
|
|
}
|
|
|
|
func TestPlan_PlaceholderGroup(t *testing.T) {
|
|
collectionID := UniqueID(0)
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
|
|
|
dslString := "{\"bool\": { \n\"vector\": {\n \"vec\": {\n \"metric_type\": \"L2\", \n \"params\": {\n \"nprobe\": 10 \n},\n \"query\": \"$0\",\"topk\": 10 \n } \n } \n } \n }"
|
|
|
|
plan, err := createPlan(*collection, dslString)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, plan)
|
|
|
|
var searchRawData1 []byte
|
|
var searchRawData2 []byte
|
|
const DIM = 16
|
|
var vec = [DIM]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
for i, ele := range vec {
|
|
buf := make([]byte, 4)
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele+float32(i*2)))
|
|
searchRawData1 = append(searchRawData1, buf...)
|
|
}
|
|
for i, ele := range vec {
|
|
buf := make([]byte, 4)
|
|
binary.LittleEndian.PutUint32(buf, math.Float32bits(ele+float32(i*4)))
|
|
searchRawData2 = append(searchRawData2, buf...)
|
|
}
|
|
placeholderValue := milvuspb.PlaceholderValue{
|
|
Tag: "$0",
|
|
Type: milvuspb.PlaceholderType_FloatVector,
|
|
Values: [][]byte{searchRawData1, searchRawData2},
|
|
}
|
|
|
|
placeholderGroup := milvuspb.PlaceholderGroup{
|
|
Placeholders: []*milvuspb.PlaceholderValue{&placeholderValue},
|
|
}
|
|
|
|
placeGroupByte, err := proto.Marshal(&placeholderGroup)
|
|
assert.Nil(t, err)
|
|
holder, err := parseSearchRequest(plan, placeGroupByte)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, holder)
|
|
numQueries := holder.getNumOfQuery()
|
|
assert.Equal(t, int(numQueries), 2)
|
|
|
|
plan.delete()
|
|
holder.delete()
|
|
deleteCollection(collection)
|
|
}
|