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_VECTOR_FLOAT, Values: [][]byte{searchRawData1, searchRawData2}, } placeholderGroup := milvuspb.PlaceholderGroup{ Placeholders: []*milvuspb.PlaceholderValue{&placeholderValue}, } placeGroupByte, err := proto.Marshal(&placeholderGroup) assert.Nil(t, err) holder, err := parserPlaceholderGroup(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) }