Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collection search cases #391

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/base/milvus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package base

import (
"context"
"fmt"
"log"
"time"

Expand Down Expand Up @@ -339,7 +340,7 @@ func (mc *MilvusClient) DeleteByPks(ctx context.Context, collName string, partit
func (mc *MilvusClient) Search(ctx context.Context, collName string, partitions []string, expr string,
outputFields []string, vectors []entity.Vector, vectorField string, metricType entity.MetricType, topK int, sp entity.SearchParam, opts ...client.SearchQueryOptionFunc) ([]client.SearchResult, error) {
var funcName = "Search"
preRequest(funcName, ctx, collName, partitions, expr, outputFields, vectors, vectorField, metricType, topK, sp, opts)
preRequest(funcName, ctx, collName, partitions, expr, outputFields, fmt.Sprintf("nq=%d", len(vectors)), vectorField, metricType, topK, sp, opts)

searchResult, err := mc.mClient.Search(ctx, collName, partitions, expr, outputFields, vectors, vectorField, metricType, topK, sp, opts...)
postResponse(funcName, err, searchResult)
Expand Down
8 changes: 5 additions & 3 deletions test/common/response_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ func CheckOutputFields(t *testing.T, actualColumns []entity.Column, expFields []
require.ElementsMatch(t, actualFields, expFields)
}

// check search result, check nq, topk, ids, score
func CheckSearchResult(t *testing.T, actualSearchResults []client.SearchResult, expNq int64, expTopk int64) {
// check search result, check nq, topK, ids, score
func CheckSearchResult(t *testing.T, actualSearchResults []client.SearchResult, expNq int, expTopK int) {
require.Equal(t, len(actualSearchResults), expNq)
for _, actualSearchResult := range actualSearchResults {
require.Equal(t, actualSearchResult.ResultCount, expTopk)
require.Equal(t, actualSearchResult.ResultCount, expTopK)
}
//expContainedIds entity.Column

}

// check persistent segments
Expand Down
23 changes: 16 additions & 7 deletions test/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
DefaultTimeout = 60
DefaultTimeout = 120
DefaultIntFieldName = "int64"
DefaultFloatFieldName = "float"
DefaultVarcharFieldName = "varchar"
Expand Down Expand Up @@ -236,14 +236,23 @@ func GenDefaultVarcharData(start int, nb int, dim int) (*entity.ColumnVarChar, *
}

// gen search vectors
func GenSearchVectors(nq int, dim int) []entity.Vector {
func GenSearchVectors(nq int, dim int, dataType entity.FieldType) []entity.Vector {
vectors := make([]entity.Vector, 0, nq)
for i := 0; i < nq; i++ {
vector := make([]float32, 0, dim)
for j := 0; j < dim; j++ {
vector = append(vector, rand.Float32())
switch dataType {
case entity.FieldTypeFloatVector:
for i := 0; i < nq; i++ {
vector := make([]float32, 0, dim)
for j := 0; j < dim; j++ {
vector = append(vector, rand.Float32())
}
vectors = append(vectors, entity.FloatVector(vector))
}
case entity.FieldTypeBinaryVector:
for i := 0; i < nq; i++ {
vector := make([]byte, dim/8)
rand.Read(vector)
vectors = append(vectors, entity.BinaryVector(vector))
}
vectors = append(vectors, entity.FloatVector(vector))
}
return vectors
}
Expand Down
4 changes: 2 additions & 2 deletions test/testcases/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ func TestDeletePartitionIdsNotMatch(t *testing.T) {

// create collection and insert [0, nb) into default partition, [nb, nb*2) into new partition
collName := createDefaultCollection(ctx, t, mc, false)
partitionName, idsDefault, _ := createInsertTwoPartitions(ctx, t, mc, collName, common.DefaultNb)
partitionName, defaultPartition, _ := createInsertTwoPartitions(ctx, t, mc, collName, common.DefaultNb)

// delete [0:10) from new partition -> delete nothing
deleteIds := entity.NewColumnInt64(common.DefaultIntFieldName, idsDefault.(*entity.ColumnInt64).Data()[:10])
deleteIds := entity.NewColumnInt64(common.DefaultIntFieldName, defaultPartition.IdsColumn.(*entity.ColumnInt64).Data()[:10])
errDelete := mc.DeleteByPks(ctx, collName, partitionName, deleteIds)
common.CheckErr(t, errDelete, true)

Expand Down
31 changes: 28 additions & 3 deletions test/testcases/flush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ import (
"github.com/stretchr/testify/require"
)

// test flush collection
func TestFlushCollection(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
// connect
mc := createMilvusClient(ctx, t)

// create default collection
collName := createDefaultCollection(ctx, t, mc, false)

// insert
intColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, common.DefaultNb, common.DefaultDim)
ids, errInsert := mc.Insert(ctx, collName, "", intColumn, floatColumn, vecColumn)
common.CheckErr(t, errInsert, true)
common.CheckInsertResult(t, ids, intColumn)

// flush and check row count
errFlush := mc.Flush(ctx, collName, false)
common.CheckErr(t, errFlush, true)
stats, _ := mc.GetCollectionStatistics(ctx, collName)
require.Equal(t, strconv.Itoa(common.DefaultNb), stats[common.RowCount])
}

// test flush empty collection
func TestFlushEmptyCollection(t *testing.T) {
ctx := createContext(t, time.Second*common.DefaultTimeout)
Expand Down Expand Up @@ -62,9 +84,12 @@ func TestFlushAsync(t *testing.T) {
for {
time.Sleep(time.Second * 1)
stats, errStatist := mc.GetCollectionStatistics(ctx, collName)
common.CheckErr(t, errStatist, true)
if strconv.Itoa(common.DefaultNb) == stats[common.RowCount] {
break
if errStatist == nil {
if strconv.Itoa(common.DefaultNb) == stats[common.RowCount] {
break
}
} else {
t.FailNow()
}
}
}
24 changes: 21 additions & 3 deletions test/testcases/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,15 @@ func createCollectionAllFields(ctx context.Context, t *testing.T, mc *base.Milvu
return collName, ids
}

func createInsertTwoPartitions(ctx context.Context, t *testing.T, mc *base.MilvusClient, collName string, nb int) (string, entity.Column, entity.Column) {
type HelpPartitionColumns struct {
PartitionName string
IdsColumn entity.Column
VectorColumn *entity.ColumnFloatVector
}

func createInsertTwoPartitions(ctx context.Context, t *testing.T, mc *base.MilvusClient, collName string, nb int) (partitionName string, defaultPartition HelpPartitionColumns, newPartition HelpPartitionColumns) {
// create new partition
partitionName := "new"
partitionName = "new"
mc.CreatePartition(ctx, collName, partitionName)

// insert nb into default partition, pks from 0 to nb
Expand All @@ -289,7 +295,19 @@ func createInsertTwoPartitions(ctx context.Context, t *testing.T, mc *base.Milvu
stats, _ := mc.GetCollectionStatistics(ctx, collName)
require.Equal(t, strconv.Itoa(nb*2), stats[common.RowCount])

return partitionName, idsDefault, idsPartition
defaultPartition = HelpPartitionColumns{
PartitionName: common.DefaultPartition,
IdsColumn: idsDefault,
VectorColumn: vecColumn,
}

newPartition = HelpPartitionColumns{
PartitionName: partitionName,
IdsColumn: idsPartition,
VectorColumn: vecColumnNew,
}

return partitionName, defaultPartition, newPartition
}

func TestMain(m *testing.M) {
Expand Down
Loading