Skip to content
Snippets Groups Projects
Select Git revision
  • ed59b60360e695700c46bd7624bcd8ed5e2f60f9
  • main default protected
  • operator-charts
  • security_enhanced_version
  • V2.1.3
  • v2.1.2
  • fix_main_deploy_doc_remote_yaml
  • fix_v2.1.0_tag
  • revert-161-fix_bug
  • v2.2.1
  • v2.2.1-alpha.3
  • v2.2.0
  • v2.2.0-beta.5
  • v2.2.0-beta.2
  • v2.2.0-beta.1
  • v2.2.0-alpha.1
  • v2.1.4
  • v2.1.3
  • v2.1.2
  • v2.1.0
  • v2.1.1-alpha
  • v2.1.0fix
  • v2.0.0
  • v1.2.0
  • v1.1.0
  • v1.0.0
26 results

main.go

Blame
  • plan_test.go 2.67 KiB
    package querynode
    
    import (
    	"encoding/binary"
    	"math"
    	"testing"
    
    	"github.com/golang/protobuf/proto"
    	"github.com/stretchr/testify/assert"
    
    	"github.com/zilliztech/milvus-distributed/internal/proto/servicepb"
    )
    
    func TestPlan_Plan(t *testing.T) {
    	collectionName := "collection0"
    	collectionID := UniqueID(0)
    	collectionMeta := genTestCollectionMeta(collectionName, collectionID)
    	schemaBlob := proto.MarshalTextString(collectionMeta.Schema)
    	assert.NotEqual(t, "", schemaBlob)
    
    	collection := newCollection(collectionMeta.ID, schemaBlob)
    
    	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) {
    	collectionName := "collection0"
    	collectionID := UniqueID(0)
    	collectionMeta := genTestCollectionMeta(collectionName, collectionID)
    	schemaBlob := proto.MarshalTextString(collectionMeta.Schema)
    	assert.NotEqual(t, "", schemaBlob)
    
    	collection := newCollection(collectionMeta.ID, schemaBlob)
    
    	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 := servicepb.PlaceholderValue{
    		Tag:    "$0",
    		Type:   servicepb.PlaceholderType_VECTOR_FLOAT,
    		Values: [][]byte{searchRawData1, searchRawData2},
    	}
    
    	placeholderGroup := servicepb.PlaceholderGroup{
    		Placeholders: []*servicepb.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)
    }