mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-29 18:38:44 +08:00
enhance: [GoSDK] Use variadic params for options (#36912)
Use variadic parameter function for options make client options easier to use. Related to #31293 Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
parent
903450f5c6
commit
e5948bd039
@ -116,7 +116,7 @@ func Count() {
|
||||
log.Println("flush done, elapsed", time.Since(start))
|
||||
|
||||
result, err := c.Query(ctx, milvusclient.NewQueryOption(collectionName).
|
||||
WithOutputFields([]string{"count(*)"}).
|
||||
WithOutputFields("count(*)").
|
||||
WithConsistencyLevel(entity.ClStrong))
|
||||
if err != nil {
|
||||
log.Fatal("failed to connect to milvus, err: ", err.Error())
|
||||
@ -125,7 +125,7 @@ func Count() {
|
||||
log.Println(rs)
|
||||
}
|
||||
result, err = c.Query(ctx, milvusclient.NewQueryOption(collectionName).
|
||||
WithOutputFields([]string{"count(*)"}).
|
||||
WithOutputFields("count(*)").
|
||||
WithFilter("id > 0").
|
||||
WithConsistencyLevel(entity.ClStrong))
|
||||
if err != nil {
|
||||
@ -136,10 +136,10 @@ func Count() {
|
||||
}
|
||||
}
|
||||
|
||||
// err = c.DropCollection(ctx, milvusclient.NewDropCollectionOption(collectionName))
|
||||
// if err != nil {
|
||||
// log.Fatal("=== Failed to drop collection", err.Error())
|
||||
// }
|
||||
err = c.DropCollection(ctx, milvusclient.NewDropCollectionOption(collectionName))
|
||||
if err != nil {
|
||||
log.Fatal("=== Failed to drop collection", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func HelloMilvus() {
|
||||
|
@ -116,7 +116,7 @@ func (opt *loadPartitionsOption) WithSkipLoadDynamicField(skipFlag bool) *loadPa
|
||||
return opt
|
||||
}
|
||||
|
||||
func NewLoadPartitionsOption(collectionName string, partitionsNames []string) *loadPartitionsOption {
|
||||
func NewLoadPartitionsOption(collectionName string, partitionsNames ...string) *loadPartitionsOption {
|
||||
return &loadPartitionsOption{
|
||||
collectionName: collectionName,
|
||||
partitionNames: partitionsNames,
|
||||
|
@ -140,7 +140,7 @@ func (s *MaintenanceSuite) TestLoadPartitions() {
|
||||
})
|
||||
defer s.mock.EXPECT().GetLoadingProgress(mock.Anything, mock.Anything).Unset()
|
||||
|
||||
task, err := s.client.LoadPartitions(ctx, NewLoadPartitionsOption(collectionName, []string{partitionName}).
|
||||
task, err := s.client.LoadPartitions(ctx, NewLoadPartitionsOption(collectionName, partitionName).
|
||||
WithReplica(replicaNum).
|
||||
WithLoadFields(fieldNames...).
|
||||
WithSkipLoadDynamicField(true))
|
||||
@ -174,7 +174,7 @@ func (s *MaintenanceSuite) TestLoadPartitions() {
|
||||
|
||||
s.mock.EXPECT().LoadPartitions(mock.Anything, mock.Anything).Return(nil, merr.WrapErrServiceInternal("mocked")).Once()
|
||||
|
||||
_, err := s.client.LoadPartitions(ctx, NewLoadPartitionsOption(collectionName, []string{partitionName}))
|
||||
_, err := s.client.LoadPartitions(ctx, NewLoadPartitionsOption(collectionName, partitionName))
|
||||
s.Error(err)
|
||||
})
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ func (c *Client) handleSearchResult(schema *entity.Schema, outputFields []string
|
||||
entry := ResultSet{
|
||||
ResultCount: rc,
|
||||
Scores: results.GetScores()[offset : offset+rc],
|
||||
sch: schema,
|
||||
}
|
||||
|
||||
entry.IDs, entry.Err = column.IDColumns(schema, results.GetIds(), offset, offset+rc)
|
||||
|
@ -121,7 +121,7 @@ func (opt *searchOption) WithOffset(offset int) *searchOption {
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *searchOption) WithOutputFields(fieldNames []string) *searchOption {
|
||||
func (opt *searchOption) WithOutputFields(fieldNames ...string) *searchOption {
|
||||
opt.outputFields = fieldNames
|
||||
return opt
|
||||
}
|
||||
@ -137,7 +137,7 @@ func (opt *searchOption) WithANNSField(annsField string) *searchOption {
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *searchOption) WithPartitions(partitionNames []string) *searchOption {
|
||||
func (opt *searchOption) WithPartitions(partitionNames ...string) *searchOption {
|
||||
opt.partitionNames = partitionNames
|
||||
return opt
|
||||
}
|
||||
@ -240,7 +240,7 @@ func (opt *queryOption) WithLimit(limit int) *queryOption {
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *queryOption) WithOutputFields(fieldNames []string) *queryOption {
|
||||
func (opt *queryOption) WithOutputFields(fieldNames ...string) *queryOption {
|
||||
opt.outputFields = fieldNames
|
||||
return opt
|
||||
}
|
||||
@ -251,7 +251,7 @@ func (opt *queryOption) WithConsistencyLevel(consistencyLevel entity.Consistency
|
||||
return opt
|
||||
}
|
||||
|
||||
func (opt *queryOption) WithPartitions(partitionNames []string) *queryOption {
|
||||
func (opt *queryOption) WithPartitions(partitionNames ...string) *queryOption {
|
||||
opt.partitionNames = partitionNames
|
||||
return opt
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func (s *ReadSuite) TestSearch() {
|
||||
entity.FloatVector(lo.RepeatBy(128, func(_ int) float32 {
|
||||
return rand.Float32()
|
||||
})),
|
||||
}).WithPartitions([]string{partitionName}))
|
||||
}).WithPartitions(partitionName))
|
||||
s.NoError(err)
|
||||
})
|
||||
|
||||
@ -109,7 +109,7 @@ func (s *ReadSuite) TestSearch() {
|
||||
entity.FloatVector(lo.RepeatBy(128, func(_ int) float32 {
|
||||
return rand.Float32()
|
||||
})),
|
||||
}).WithPartitions([]string{partitionName}))
|
||||
}).WithPartitions(partitionName))
|
||||
s.NoError(err)
|
||||
})
|
||||
|
||||
@ -145,7 +145,7 @@ func (s *ReadSuite) TestQuery() {
|
||||
return &milvuspb.QueryResults{}, nil
|
||||
}).Once()
|
||||
|
||||
_, err := s.client.Query(ctx, NewQueryOption(collectionName).WithPartitions([]string{partitionName}))
|
||||
_, err := s.client.Query(ctx, NewQueryOption(collectionName).WithPartitions(partitionName))
|
||||
s.NoError(err)
|
||||
})
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package client
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
|
||||
@ -64,7 +65,7 @@ func (sr *ResultSet) Unmarshal(receiver any) (err error) {
|
||||
func (sr *ResultSet) fillPKEntry(receiver any) (err error) {
|
||||
defer func() {
|
||||
if x := recover(); x != nil {
|
||||
err = errors.Newf("failed to unmarshal result set: %v", x)
|
||||
err = errors.Newf("failed to unmarshal result set: %v, stack: %v", x, string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
rr := reflect.ValueOf(receiver)
|
||||
@ -132,7 +133,7 @@ func (ds DataSet) Len() int {
|
||||
func (ds DataSet) Unmarshal(receiver any) (err error) {
|
||||
defer func() {
|
||||
if x := recover(); x != nil {
|
||||
err = errors.Newf("failed to unmarshal result set: %v", x)
|
||||
err = errors.Newf("failed to unmarshal result set: %v, stack: %v", x, string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
rr := reflect.ValueOf(receiver)
|
||||
|
@ -158,7 +158,7 @@ func TestDeleteComplexExprWithoutLoad(t *testing.T) {
|
||||
prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName))
|
||||
|
||||
res, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(fmt.Sprintf("%s >= 0 ", common.DefaultInt64FieldName)).
|
||||
WithOutputFields([]string{common.QueryCountFieldName}).WithConsistencyLevel(entity.ClStrong))
|
||||
WithOutputFields(common.QueryCountFieldName).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
count, _ := res.Fields[0].GetAsInt64(0)
|
||||
require.Equal(t, int64(common.DefaultNb-5), count)
|
||||
@ -324,7 +324,7 @@ func TestDeleteDefaultPartitionName(t *testing.T) {
|
||||
common.CheckErr(t, errQuery, true)
|
||||
require.Zero(t, queryRes.ResultCount)
|
||||
|
||||
queryRes, errQuery = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithPartitions([]string{common.DefaultPartition, parName}).
|
||||
queryRes, errQuery = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithPartitions(common.DefaultPartition, parName).
|
||||
WithConsistencyLevel(entity.ClStrong).WithFilter(expr))
|
||||
common.CheckErr(t, errQuery, true)
|
||||
require.Zero(t, queryRes.ResultCount)
|
||||
@ -362,7 +362,7 @@ func TestDeleteEmptyPartitionName(t *testing.T) {
|
||||
common.CheckErr(t, errQuery, true)
|
||||
require.Zero(t, queryRes.ResultCount)
|
||||
|
||||
queryRes, errQuery = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithPartitions([]string{common.DefaultPartition, parName}).
|
||||
queryRes, errQuery = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithPartitions(common.DefaultPartition, parName).
|
||||
WithConsistencyLevel(entity.ClStrong).WithFilter(expr))
|
||||
common.CheckErr(t, errQuery, true)
|
||||
require.Zero(t, queryRes.ResultCount)
|
||||
@ -406,7 +406,7 @@ func TestDeletePartitionName(t *testing.T) {
|
||||
require.Equal(t, int64(0), del2.DeleteCount)
|
||||
|
||||
// query and verify
|
||||
resQuery, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(exprQuery).WithOutputFields([]string{common.QueryCountFieldName}).
|
||||
resQuery, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(exprQuery).WithOutputFields(common.QueryCountFieldName).
|
||||
WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
count, _ := resQuery.Fields[0].GetAsInt64(0)
|
||||
@ -427,7 +427,7 @@ func TestDeletePartitionName(t *testing.T) {
|
||||
require.Equal(t, common.DefaultNb*2-200-1500, queryRes.ResultCount)
|
||||
|
||||
queryRes, errQuery = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(exprQuery).WithConsistencyLevel(entity.ClStrong).
|
||||
WithPartitions([]string{common.DefaultPartition, parName}))
|
||||
WithPartitions(common.DefaultPartition, parName))
|
||||
common.CheckErr(t, errQuery, true)
|
||||
require.Equal(t, common.DefaultNb*2-200-1500, queryRes.ResultCount)
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ func TestCreateAutoIndexAllFields(t *testing.T) {
|
||||
// load -> search and output all vector fields
|
||||
prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName))
|
||||
queryVec := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithANNSField(common.DefaultFloatVecFieldName).WithOutputFields([]string{"*"}))
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithANNSField(common.DefaultFloatVecFieldName).WithOutputFields("*"))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckOutputFields(t, expFields, searchRes[0].Fields)
|
||||
}
|
||||
@ -483,7 +483,7 @@ func TestCreateSortedScalarIndex(t *testing.T) {
|
||||
|
||||
queryVec := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
expr := fmt.Sprintf("%s > 10", common.DefaultInt64FieldName)
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithFilter(expr).WithOutputFields([]string{"*"}))
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithFilter(expr).WithOutputFields("*"))
|
||||
common.CheckErr(t, err, true)
|
||||
expFields := make([]string, 0, len(schema.Fields))
|
||||
for _, field := range schema.Fields {
|
||||
@ -526,7 +526,7 @@ func TestCreateInvertedScalarIndex(t *testing.T) {
|
||||
|
||||
queryVec := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
expr := fmt.Sprintf("%s > 10", common.DefaultInt64FieldName)
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithFilter(expr).WithOutputFields([]string{"*"}))
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithFilter(expr).WithOutputFields("*"))
|
||||
common.CheckErr(t, err, true)
|
||||
expFields := make([]string, 0, len(schema.Fields))
|
||||
for _, field := range schema.Fields {
|
||||
@ -691,7 +691,7 @@ func TestCreateInvertedIndexArrayField(t *testing.T) {
|
||||
// load -> search and output all fields
|
||||
prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName))
|
||||
queryVec := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
searchRes, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithConsistencyLevel(entity.ClStrong).WithOutputFields([]string{"*"}))
|
||||
searchRes, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithConsistencyLevel(entity.ClStrong).WithOutputFields("*"))
|
||||
common.CheckErr(t, errSearch, true)
|
||||
var expFields []string
|
||||
for _, field := range schema.Fields {
|
||||
|
@ -176,7 +176,7 @@ func TestInsertDynamicExtraColumn(t *testing.T) {
|
||||
common.CheckErr(t, err, true)
|
||||
|
||||
// query
|
||||
res, _ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter("int64 == 3000").WithOutputFields([]string{"*"}))
|
||||
res, _ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter("int64 == 3000").WithOutputFields("*"))
|
||||
common.CheckOutputFields(t, []string{common.DefaultFloatVecFieldName, common.DefaultInt64FieldName, common.DefaultDynamicFieldName}, res.Fields)
|
||||
for _, c := range res.Fields {
|
||||
log.Debug("data", zap.Any("data", c.FieldData()))
|
||||
@ -454,7 +454,7 @@ func TestInsertReadSparseEmptyVector(t *testing.T) {
|
||||
require.EqualValues(t, 1, insertRes.InsertCount)
|
||||
|
||||
// query and check vector is empty
|
||||
resQuery, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithLimit(10).WithOutputFields([]string{common.DefaultSparseVecFieldName}).WithConsistencyLevel(entity.ClStrong))
|
||||
resQuery, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithLimit(10).WithOutputFields(common.DefaultSparseVecFieldName).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
require.Equal(t, 1, resQuery.ResultCount)
|
||||
log.Info("sparseVec", zap.Any("data", resQuery.GetColumn(common.DefaultSparseVecFieldName).(*column.ColumnSparseFloatVector).Data()))
|
||||
|
@ -183,7 +183,7 @@ func TestDropPartitionData(t *testing.T) {
|
||||
|
||||
// insert data into partition -> query check
|
||||
prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema).TWithPartitionName(parName), hp.TNewDataOption())
|
||||
res, errQ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithPartitions([]string{parName}).WithOutputFields([]string{common.QueryCountFieldName}))
|
||||
res, errQ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithPartitions(parName).WithOutputFields(common.QueryCountFieldName))
|
||||
common.CheckErr(t, errQ, true)
|
||||
count, _ := res.GetColumn(common.QueryCountFieldName).Get(0)
|
||||
require.EqualValues(t, common.DefaultNb, count)
|
||||
|
@ -73,7 +73,7 @@ func TestQueryNotExistName(t *testing.T) {
|
||||
prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName))
|
||||
|
||||
// query with not existed partition
|
||||
_, errPar := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions([]string{"aaa"}))
|
||||
_, errPar := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions("aaa"))
|
||||
common.CheckErr(t, errPar, false, "partition name aaa not found")
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ func TestQueryInvalidPartitionName(t *testing.T) {
|
||||
expr := fmt.Sprintf("%s >= %d", common.DefaultInt64FieldName, 0)
|
||||
emptyPartitionName := ""
|
||||
// query from "" partitions, expect to query from default partition
|
||||
_, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions([]string{emptyPartitionName}))
|
||||
_, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions(emptyPartitionName))
|
||||
common.CheckErr(t, err, false, "Partition name should not be empty")
|
||||
}
|
||||
|
||||
@ -122,22 +122,22 @@ func TestQueryPartition(t *testing.T) {
|
||||
common.CheckQueryResult(t, queryRes.Fields, []column.Column{expColumn})
|
||||
|
||||
// query with empty partition names
|
||||
queryRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions([]string{}).WithConsistencyLevel(entity.ClStrong))
|
||||
queryRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions().WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, queryRes.Fields, []column.Column{expColumn})
|
||||
|
||||
// query with default partition
|
||||
queryRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions([]string{common.DefaultPartition}).WithConsistencyLevel(entity.ClStrong))
|
||||
queryRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions(common.DefaultPartition).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, queryRes.Fields, []column.Column{i1Res.IDs})
|
||||
|
||||
// query with specify partition
|
||||
queryRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions([]string{parName}).WithConsistencyLevel(entity.ClStrong))
|
||||
queryRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions(parName).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, queryRes.Fields, []column.Column{i2Res.IDs})
|
||||
|
||||
// query with all partitions
|
||||
queryRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions([]string{common.DefaultPartition, parName}).WithConsistencyLevel(entity.ClStrong))
|
||||
queryRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithPartitions(common.DefaultPartition, parName).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, queryRes.Fields, []column.Column{expColumn})
|
||||
}
|
||||
@ -181,12 +181,12 @@ func TestQueryOutputFields(t *testing.T) {
|
||||
expr := fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, 10)
|
||||
|
||||
// query with empty output fields []string{}-> output "int64"
|
||||
queryNilOutputs, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields([]string{}))
|
||||
queryNilOutputs, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields())
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckOutputFields(t, []string{common.DefaultInt64FieldName}, queryNilOutputs.Fields)
|
||||
|
||||
// query with empty output fields []string{""}-> output "int64" and dynamic field
|
||||
_, err1 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields([]string{""}))
|
||||
_, err1 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields(""))
|
||||
if enableDynamic {
|
||||
common.CheckErr(t, err1, false, "parse output field name failed")
|
||||
} else {
|
||||
@ -195,7 +195,7 @@ func TestQueryOutputFields(t *testing.T) {
|
||||
|
||||
// query with not existed field -> output field as dynamic or error
|
||||
fakeName := "aaa"
|
||||
res2, err2 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields([]string{fakeName}))
|
||||
res2, err2 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields(fakeName))
|
||||
if enableDynamic {
|
||||
common.CheckErr(t, err2, true)
|
||||
for _, c := range res2.Fields {
|
||||
@ -213,7 +213,7 @@ func TestQueryOutputFields(t *testing.T) {
|
||||
}
|
||||
|
||||
// query with part not existed field ["aa", "$meat"]: error or as dynamic field
|
||||
res3, err3 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields([]string{fakeName, common.DefaultDynamicFieldName}))
|
||||
res3, err3 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields(fakeName, common.DefaultDynamicFieldName))
|
||||
if enableDynamic {
|
||||
common.CheckErr(t, err3, true)
|
||||
common.CheckOutputFields(t, []string{common.DefaultInt64FieldName, fakeName, common.DefaultDynamicFieldName}, res3.Fields)
|
||||
@ -222,7 +222,7 @@ func TestQueryOutputFields(t *testing.T) {
|
||||
}
|
||||
|
||||
// query with repeated field: ["*", "$meat"], ["floatVec", floatVec"] unique field
|
||||
res4, err4 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields([]string{"*", common.DefaultDynamicFieldName}))
|
||||
res4, err4 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields("*", common.DefaultDynamicFieldName))
|
||||
if enableDynamic {
|
||||
common.CheckErr(t, err4, true)
|
||||
common.CheckOutputFields(t, []string{common.DefaultInt64FieldName, common.DefaultFloatVecFieldName, common.DefaultDynamicFieldName}, res4.Fields)
|
||||
@ -230,8 +230,7 @@ func TestQueryOutputFields(t *testing.T) {
|
||||
common.CheckErr(t, err4, false, "$meta not exist")
|
||||
}
|
||||
|
||||
res5, err5 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields(
|
||||
[]string{common.DefaultFloatVecFieldName, common.DefaultFloatVecFieldName, common.DefaultInt64FieldName}))
|
||||
res5, err5 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields(common.DefaultFloatVecFieldName, common.DefaultFloatVecFieldName, common.DefaultInt64FieldName))
|
||||
common.CheckErr(t, err5, true)
|
||||
common.CheckOutputFields(t, []string{common.DefaultInt64FieldName, common.DefaultFloatVecFieldName}, res5.Fields)
|
||||
}
|
||||
@ -277,7 +276,7 @@ func TestQueryOutputAllFieldsColumn(t *testing.T) {
|
||||
allFieldsName = append(allFieldsName, common.DefaultDynamicFieldName)
|
||||
}
|
||||
queryResultAll, errQuery := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, pos)).WithOutputFields([]string{"*"}))
|
||||
WithFilter(fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, pos)).WithOutputFields("*"))
|
||||
common.CheckErr(t, errQuery, true)
|
||||
common.CheckOutputFields(t, allFieldsName, queryResultAll.Fields)
|
||||
|
||||
@ -318,7 +317,7 @@ func TestQueryOutputAllFieldsRows(t *testing.T) {
|
||||
allFieldsName = append(allFieldsName, field.Name)
|
||||
}
|
||||
queryResultAll, errQuery := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, 10)).WithOutputFields([]string{"*"}))
|
||||
WithFilter(fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, 10)).WithOutputFields("*"))
|
||||
common.CheckErr(t, errQuery, true)
|
||||
common.CheckOutputFields(t, allFieldsName, queryResultAll.Fields)
|
||||
}
|
||||
@ -348,7 +347,7 @@ func TestQueryOutputBinaryAndVarchar(t *testing.T) {
|
||||
expr := fmt.Sprintf("%s in ['0', '1', '2', '3', '4', '5'] ", common.DefaultVarcharFieldName)
|
||||
allFieldsName := []string{common.DefaultVarcharFieldName, common.DefaultBinaryVecFieldName, common.DefaultDynamicFieldName}
|
||||
queryResultAll, errQuery := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(expr).WithOutputFields([]string{"*"}))
|
||||
WithFilter(expr).WithOutputFields("*"))
|
||||
common.CheckErr(t, errQuery, true)
|
||||
common.CheckOutputFields(t, allFieldsName, queryResultAll.Fields)
|
||||
|
||||
@ -383,7 +382,7 @@ func TestQueryOutputSparse(t *testing.T) {
|
||||
// query output all fields -> output all fields, includes vector and $meta field
|
||||
expr := fmt.Sprintf("%s < 100 ", common.DefaultInt64FieldName)
|
||||
expFieldsName := []string{common.DefaultInt64FieldName, common.DefaultVarcharFieldName, common.DefaultSparseVecFieldName}
|
||||
queryResultAll, errQuery := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields([]string{"*"}))
|
||||
queryResultAll, errQuery := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields("*"))
|
||||
common.CheckErr(t, errQuery, true)
|
||||
common.CheckOutputFields(t, expFieldsName, queryResultAll.Fields)
|
||||
|
||||
@ -423,19 +422,19 @@ func TestQueryArrayDifferentLenBetweenRows(t *testing.T) {
|
||||
|
||||
// query array idx exceeds max capacity, array[200]
|
||||
expr := fmt.Sprintf("%s[%d] > 0", common.DefaultInt64ArrayField, common.TestCapacity*2)
|
||||
countRes, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields([]string{common.QueryCountFieldName}))
|
||||
countRes, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields(common.QueryCountFieldName))
|
||||
common.CheckErr(t, err, true)
|
||||
count, _ := countRes.Fields[0].GetAsInt64(0)
|
||||
require.Equal(t, int64(0), count)
|
||||
|
||||
countRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields([]string{"Count(*)"}))
|
||||
countRes, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr).WithOutputFields("Count(*)"))
|
||||
common.CheckErr(t, err, true)
|
||||
count, _ = countRes.Fields[0].GetAsInt64(0)
|
||||
require.Equal(t, int64(0), count)
|
||||
|
||||
// query: some rows has element greater than expr index array[100]
|
||||
expr2 := fmt.Sprintf("%s[%d] > 0", common.DefaultInt64ArrayField, common.TestCapacity)
|
||||
countRes2, err2 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr2).WithOutputFields([]string{common.QueryCountFieldName}))
|
||||
countRes2, err2 := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(expr2).WithOutputFields(common.QueryCountFieldName))
|
||||
common.CheckErr(t, err2, true)
|
||||
count2, _ := countRes2.Fields[0].GetAsInt64(0)
|
||||
require.Equal(t, int64(common.DefaultNb), count2)
|
||||
@ -456,7 +455,7 @@ func TestQueryJsonDynamicExpr(t *testing.T) {
|
||||
expr := fmt.Sprintf("%s['number'] < 10 || %s < 10", common.DefaultJSONFieldName, common.DefaultDynamicNumberField)
|
||||
|
||||
queryRes, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithConsistencyLevel(entity.ClStrong).
|
||||
WithOutputFields([]string{common.DefaultJSONFieldName, common.DefaultDynamicFieldName}))
|
||||
WithOutputFields(common.DefaultJSONFieldName, common.DefaultDynamicFieldName))
|
||||
|
||||
// verify output fields and count, dynamicNumber value
|
||||
common.CheckErr(t, err, true)
|
||||
@ -557,7 +556,7 @@ func TestQueryCountJsonDynamicExpr(t *testing.T) {
|
||||
|
||||
for _, _exprCount := range exprCounts {
|
||||
log.Debug("TestQueryCountJsonDynamicExpr", zap.String("expr", _exprCount.expr))
|
||||
countRes, _ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(_exprCount.expr).WithOutputFields([]string{common.QueryCountFieldName}))
|
||||
countRes, _ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(_exprCount.expr).WithOutputFields(common.QueryCountFieldName))
|
||||
count, _ := countRes.Fields[0].GetAsInt64(0)
|
||||
require.Equal(t, _exprCount.count, count)
|
||||
}
|
||||
@ -600,7 +599,7 @@ func TestQueryArrayFieldExpr(t *testing.T) {
|
||||
|
||||
for _, _exprCount := range exprCounts {
|
||||
log.Debug("TestQueryCountJsonDynamicExpr", zap.String("expr", _exprCount.expr))
|
||||
countRes, _ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(_exprCount.expr).WithOutputFields([]string{common.QueryCountFieldName}))
|
||||
countRes, _ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(_exprCount.expr).WithOutputFields(common.QueryCountFieldName))
|
||||
count, _ := countRes.Fields[0].GetAsInt64(0)
|
||||
require.Equal(t, _exprCount.count, count)
|
||||
}
|
||||
@ -632,7 +631,7 @@ func TestQueryOutputInvalidOutputFieldCount(t *testing.T) {
|
||||
queryExpr := fmt.Sprintf("%s >= 0", common.DefaultInt64FieldName)
|
||||
|
||||
// query with empty output fields []string{}-> output "int64"
|
||||
_, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(queryExpr).WithOutputFields([]string{invalidCount.countField}))
|
||||
_, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithFilter(queryExpr).WithOutputFields(invalidCount.countField))
|
||||
common.CheckErr(t, err, false, invalidCount.errMsg)
|
||||
}
|
||||
}
|
||||
|
@ -69,12 +69,12 @@ func TestSearchInvalidCollectionPartitionName(t *testing.T) {
|
||||
|
||||
// search with not exist partition
|
||||
_, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption())
|
||||
_, err1 := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithPartitions([]string{"aaa"}))
|
||||
_, err1 := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithPartitions("aaa"))
|
||||
common.CheckErr(t, err1, false, "partition name aaa not found")
|
||||
|
||||
// search with empty partition name []string{""} -> error
|
||||
_, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).
|
||||
WithConsistencyLevel(entity.ClStrong).WithANNSField(common.DefaultFloatVecFieldName).WithPartitions([]string{""}))
|
||||
WithConsistencyLevel(entity.ClStrong).WithANNSField(common.DefaultFloatVecFieldName).WithPartitions(""))
|
||||
common.CheckErr(t, errSearch, false, "Partition name should not be empty")
|
||||
}
|
||||
|
||||
@ -160,7 +160,7 @@ func TestSearchPartitions(t *testing.T) {
|
||||
// query first ID of _default and parName partition
|
||||
_defId0, _ := insertRes1.IDs.GetAsInt64(0)
|
||||
_parId0, _ := insertRes2.IDs.GetAsInt64(0)
|
||||
queryRes, _ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(fmt.Sprintf("int64 in [%d, %d]", _defId0, _parId0)).WithOutputFields([]string{"*"}))
|
||||
queryRes, _ := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(fmt.Sprintf("int64 in [%d, %d]", _defId0, _parId0)).WithOutputFields("*"))
|
||||
require.ElementsMatch(t, []int64{_defId0, _parId0}, queryRes.GetColumn(common.DefaultInt64FieldName).(*column.ColumnInt64).Data())
|
||||
for _, vec := range queryRes.GetColumn(common.DefaultFloatVecFieldName).(*column.ColumnFloatVector).Data() {
|
||||
vectors = append(vectors, entity.FloatVector(vec))
|
||||
@ -169,7 +169,7 @@ func TestSearchPartitions(t *testing.T) {
|
||||
for _, partitions := range [][]string{{}, {common.DefaultPartition, parName}} {
|
||||
// search with empty partition names slice []string{} -> all partitions
|
||||
searchResult, errSearch1 := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, 5, vectors).
|
||||
WithConsistencyLevel(entity.ClStrong).WithANNSField(common.DefaultFloatVecFieldName).WithPartitions(partitions).WithOutputFields([]string{"*"}))
|
||||
WithConsistencyLevel(entity.ClStrong).WithANNSField(common.DefaultFloatVecFieldName).WithPartitions(partitions...).WithOutputFields("*"))
|
||||
|
||||
// check search result contains search vector, which from all partitions
|
||||
common.CheckErr(t, errSearch1, true)
|
||||
@ -196,12 +196,12 @@ func TestSearchEmptyOutputFields(t *testing.T) {
|
||||
prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName))
|
||||
|
||||
vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
resSearch, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields([]string{}))
|
||||
resSearch, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields())
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckSearchResult(t, resSearch, common.DefaultNq, common.DefaultLimit)
|
||||
common.CheckOutputFields(t, []string{}, resSearch[0].Fields)
|
||||
|
||||
_, err = mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields([]string{""}))
|
||||
_, err = mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields(""))
|
||||
if dynamic {
|
||||
common.CheckErr(t, err, false, "parse output field name failed")
|
||||
} else {
|
||||
@ -238,7 +238,7 @@ func TestSearchNotExistOutputFields(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, _dof := range dof {
|
||||
resSearch, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields(_dof.outputFields))
|
||||
resSearch, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields(_dof.outputFields...))
|
||||
if enableDynamic {
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckSearchResult(t, resSearch, common.DefaultNq, common.DefaultLimit)
|
||||
@ -248,7 +248,7 @@ func TestSearchNotExistOutputFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
existedRepeatedFields := []string{common.DefaultInt64FieldName, common.DefaultFloatVecFieldName, common.DefaultInt64FieldName, common.DefaultFloatVecFieldName}
|
||||
resSearch2, err2 := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields(existedRepeatedFields))
|
||||
resSearch2, err2 := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields(existedRepeatedFields...))
|
||||
common.CheckErr(t, err2, true)
|
||||
common.CheckSearchResult(t, resSearch2, common.DefaultNq, common.DefaultLimit)
|
||||
common.CheckOutputFields(t, []string{common.DefaultInt64FieldName, common.DefaultFloatVecFieldName}, resSearch2[0].Fields)
|
||||
@ -275,7 +275,7 @@ func TestSearchOutputAllFields(t *testing.T) {
|
||||
vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).
|
||||
WithANNSField(common.DefaultFloatVecFieldName).WithOutputFields([]string{"*"}))
|
||||
WithANNSField(common.DefaultFloatVecFieldName).WithOutputFields("*"))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit)
|
||||
for _, res := range searchRes {
|
||||
@ -301,7 +301,7 @@ func TestSearchOutputBinaryPk(t *testing.T) {
|
||||
allFieldsName = append(allFieldsName, field.Name)
|
||||
}
|
||||
vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeBinaryVector)
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields([]string{"*"}))
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).WithOutputFields("*"))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit)
|
||||
for _, res := range searchRes {
|
||||
@ -328,7 +328,7 @@ func TestSearchOutputSparse(t *testing.T) {
|
||||
}
|
||||
vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeSparseVector)
|
||||
searchRes, err := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).
|
||||
WithANNSField(common.DefaultSparseVecFieldName).WithOutputFields([]string{"*"}))
|
||||
WithANNSField(common.DefaultSparseVecFieldName).WithOutputFields("*"))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit)
|
||||
for _, res := range searchRes {
|
||||
@ -675,7 +675,7 @@ func TestSearchJsonFieldExpr(t *testing.T) {
|
||||
log.Debug("TestSearchJsonFieldExpr", zap.String("expr", expr))
|
||||
vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
searchRes, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(expr).WithANNSField(common.DefaultFloatVecFieldName).WithOutputFields([]string{common.DefaultInt64FieldName, common.DefaultJSONFieldName}))
|
||||
WithFilter(expr).WithANNSField(common.DefaultFloatVecFieldName).WithOutputFields(common.DefaultInt64FieldName, common.DefaultJSONFieldName))
|
||||
common.CheckErr(t, errSearch, true)
|
||||
common.CheckOutputFields(t, []string{common.DefaultInt64FieldName, common.DefaultJSONFieldName}, searchRes[0].Fields)
|
||||
common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit)
|
||||
@ -710,7 +710,7 @@ func TestSearchDynamicFieldExpr(t *testing.T) {
|
||||
log.Debug("TestSearchDynamicFieldExpr", zap.String("expr", expr))
|
||||
vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
searchRes, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(expr).WithANNSField(common.DefaultFloatVecFieldName).WithOutputFields([]string{common.DefaultInt64FieldName, "dynamicNumber", "number"}))
|
||||
WithFilter(expr).WithANNSField(common.DefaultFloatVecFieldName).WithOutputFields(common.DefaultInt64FieldName, "dynamicNumber", "number"))
|
||||
common.CheckErr(t, errSearch, true)
|
||||
common.CheckOutputFields(t, []string{common.DefaultInt64FieldName, "dynamicNumber", "number"}, searchRes[0].Fields)
|
||||
if expr == "$meta['dynamicString'] == '1'" {
|
||||
@ -733,7 +733,7 @@ func TestSearchDynamicFieldExpr(t *testing.T) {
|
||||
vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
searchRes, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(expr).WithANNSField(common.DefaultFloatVecFieldName).
|
||||
WithOutputFields([]string{common.DefaultInt64FieldName, common.DefaultJSONFieldName, common.DefaultDynamicFieldName, "dynamicNumber", "number"}))
|
||||
WithOutputFields(common.DefaultInt64FieldName, common.DefaultJSONFieldName, common.DefaultDynamicFieldName, "dynamicNumber", "number"))
|
||||
common.CheckErr(t, errSearch, true)
|
||||
common.CheckOutputFields(t, []string{common.DefaultInt64FieldName, common.DefaultJSONFieldName, common.DefaultDynamicFieldName, "dynamicNumber", "number"}, searchRes[0].Fields)
|
||||
for _, res := range searchRes {
|
||||
@ -779,7 +779,7 @@ func TestSearchArrayFieldExpr(t *testing.T) {
|
||||
vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector)
|
||||
for _, expr := range exprs {
|
||||
searchRes, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(expr).WithOutputFields(allArrayFields))
|
||||
WithFilter(expr).WithOutputFields(allArrayFields...))
|
||||
common.CheckErr(t, errSearch, true)
|
||||
common.CheckOutputFields(t, allArrayFields, searchRes[0].Fields)
|
||||
common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit)
|
||||
@ -787,7 +787,7 @@ func TestSearchArrayFieldExpr(t *testing.T) {
|
||||
|
||||
// search hits empty
|
||||
searchRes, errSearchEmpty := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(fmt.Sprintf("array_contains (%s, 1000000)", common.DefaultInt32ArrayField)).WithOutputFields(allArrayFields))
|
||||
WithFilter(fmt.Sprintf("array_contains (%s, 1000000)", common.DefaultInt32ArrayField)).WithOutputFields(allArrayFields...))
|
||||
common.CheckErr(t, errSearchEmpty, true)
|
||||
common.CheckSearchResult(t, searchRes, common.DefaultNq, 0)
|
||||
}
|
||||
@ -858,7 +858,7 @@ func TestSearchMultiVectors(t *testing.T) {
|
||||
expr := fmt.Sprintf("%s > 10", common.DefaultInt64FieldName)
|
||||
|
||||
resSearch, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit*2, queryVec).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(expr).WithANNSField(fnt.fieldName).WithOutputFields([]string{"*"}))
|
||||
WithFilter(expr).WithANNSField(fnt.fieldName).WithOutputFields("*"))
|
||||
common.CheckErr(t, errSearch, true)
|
||||
common.CheckSearchResult(t, resSearch, common.DefaultNq, common.DefaultLimit*2)
|
||||
common.CheckOutputFields(t, []string{
|
||||
@ -868,7 +868,7 @@ func TestSearchMultiVectors(t *testing.T) {
|
||||
|
||||
// pagination search
|
||||
resPage, errPage := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithConsistencyLevel(entity.ClStrong).
|
||||
WithFilter(expr).WithANNSField(fnt.fieldName).WithOutputFields([]string{"*"}).WithOffset(10))
|
||||
WithFilter(expr).WithANNSField(fnt.fieldName).WithOutputFields("*").WithOffset(10))
|
||||
|
||||
common.CheckErr(t, errPage, true)
|
||||
common.CheckSearchResult(t, resPage, common.DefaultNq, common.DefaultLimit)
|
||||
@ -903,7 +903,7 @@ func TestSearchSparseVector(t *testing.T) {
|
||||
// search
|
||||
queryVec := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeSparseVector)
|
||||
resSearch, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithConsistencyLevel(entity.ClStrong).
|
||||
WithOutputFields([]string{"*"}))
|
||||
WithOutputFields("*"))
|
||||
|
||||
common.CheckErr(t, errSearch, true)
|
||||
require.Len(t, resSearch, common.DefaultNq)
|
||||
@ -1040,12 +1040,12 @@ func TestSearchSparseVectorPagination(t *testing.T) {
|
||||
// search
|
||||
queryVec := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeSparseVector)
|
||||
resSearch, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithConsistencyLevel(entity.ClStrong).
|
||||
WithOutputFields([]string{"*"}))
|
||||
WithOutputFields("*"))
|
||||
common.CheckErr(t, errSearch, true)
|
||||
require.Len(t, resSearch, common.DefaultNq)
|
||||
|
||||
pageSearch, errSearch := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, queryVec).WithConsistencyLevel(entity.ClStrong).
|
||||
WithOutputFields([]string{"*"}).WithOffset(5))
|
||||
WithOutputFields("*").WithOffset(5))
|
||||
common.CheckErr(t, errSearch, true)
|
||||
require.Len(t, pageSearch, common.DefaultNq)
|
||||
for i := 0; i < len(resSearch); i++ {
|
||||
|
@ -47,7 +47,7 @@ func TestUpsertAllFields(t *testing.T) {
|
||||
require.EqualValues(t, upsertNb, upsertRes.UpsertCount)
|
||||
|
||||
expr := fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, upsertNb)
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, append(columns, hp.MergeColumnsToDynamic(upsertNb, dynamicColumns, common.DefaultDynamicFieldName)), resSet.Fields)
|
||||
|
||||
@ -69,7 +69,7 @@ func TestUpsertAllFields(t *testing.T) {
|
||||
require.EqualValues(t, newUpsertNb, upsertResPart.UpsertCount)
|
||||
|
||||
newExpr := fmt.Sprintf("%d <= %s < %d", newUpsertStart, common.DefaultInt64FieldName, newUpsertNb+newUpsertStart)
|
||||
resSetPart, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(newExpr).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSetPart, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(newExpr).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, append(columnsPart, hp.MergeColumnsToDynamic(newUpsertNb, dynamicColumnsPart, common.DefaultDynamicFieldName)), resSetPart.Fields)
|
||||
|
||||
@ -80,7 +80,7 @@ func TestUpsertAllFields(t *testing.T) {
|
||||
require.EqualValues(t, newUpsertStart, upsertResNot.UpsertCount)
|
||||
|
||||
newExprNot := fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, newUpsertStart)
|
||||
resSetNot, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(newExprNot).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSetNot, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(newExprNot).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, append(columnsNot, hp.MergeColumnsToDynamic(newUpsertStart, dynamicColumnsNot, common.DefaultDynamicFieldName)), resSetNot.Fields)
|
||||
}
|
||||
@ -117,7 +117,7 @@ func TestUpsertSparse(t *testing.T) {
|
||||
prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName))
|
||||
|
||||
expr := fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, upsertNb)
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, append(columns, hp.MergeColumnsToDynamic(upsertNb, dynamicColumns, common.DefaultDynamicFieldName)), resSet.Fields)
|
||||
|
||||
@ -139,7 +139,7 @@ func TestUpsertSparse(t *testing.T) {
|
||||
require.EqualValues(t, newUpsertNb, upsertResPart.UpsertCount)
|
||||
|
||||
newExpr := fmt.Sprintf("%d <= %s < %d", newUpsertStart, common.DefaultInt64FieldName, newUpsertNb+newUpsertStart)
|
||||
resSetPart, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(newExpr).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSetPart, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(newExpr).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, append(columnsPart, hp.MergeColumnsToDynamic(newUpsertNb, dynamicColumnsPart, common.DefaultDynamicFieldName)), resSetPart.Fields)
|
||||
|
||||
@ -150,7 +150,7 @@ func TestUpsertSparse(t *testing.T) {
|
||||
require.EqualValues(t, newUpsertStart, upsertResNot.UpsertCount)
|
||||
|
||||
newExprNot := fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, newUpsertStart)
|
||||
resSetNot, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(newExprNot).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSetNot, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(newExprNot).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, append(columnsNot, hp.MergeColumnsToDynamic(newUpsertStart, dynamicColumnsNot, common.DefaultDynamicFieldName)), resSetNot.Fields)
|
||||
}
|
||||
@ -181,7 +181,7 @@ func TestUpsertVarcharPk(t *testing.T) {
|
||||
|
||||
// query and verify the updated entities
|
||||
expr := fmt.Sprintf("%s in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] ", common.DefaultVarcharFieldName)
|
||||
resSet1, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSet1, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, []column.Column{varcharColumn, binaryColumn}, resSet1.Fields)
|
||||
|
||||
@ -197,13 +197,13 @@ func TestUpsertVarcharPk(t *testing.T) {
|
||||
common.EqualColumn(t, varcharColumn1, upsertRes1.IDs)
|
||||
|
||||
// query old varchar pk (no space): ["1", ... "9"]
|
||||
resSet2, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSet2, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, []column.Column{varcharColumn, binaryColumn}, resSet2.Fields)
|
||||
|
||||
// query and verify the updated entities
|
||||
exprNew := fmt.Sprintf("%s like ' %% ' ", common.DefaultVarcharFieldName)
|
||||
resSet3, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(exprNew).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSet3, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(exprNew).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, []column.Column{varcharColumn1, binaryColumn1}, resSet3.Fields)
|
||||
}
|
||||
@ -232,7 +232,7 @@ func TestUpsertMultiPartitions(t *testing.T) {
|
||||
|
||||
// query and verify
|
||||
expr := fmt.Sprintf("%d <= %s < %d", common.DefaultNb, common.DefaultInt64FieldName, common.DefaultNb+200)
|
||||
resSet3, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
resSet3, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(expr).WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
expColumns := []column.Column{hp.MergeColumnsToDynamic(200, dynamicColumns, common.DefaultDynamicFieldName)}
|
||||
for _, c := range columns {
|
||||
@ -268,7 +268,7 @@ func TestUpsertSamePksManyTimes(t *testing.T) {
|
||||
|
||||
// query and verify the updated entities
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, upsertNb)).
|
||||
WithOutputFields([]string{common.DefaultFloatVecFieldName}).WithConsistencyLevel(entity.ClStrong))
|
||||
WithOutputFields(common.DefaultFloatVecFieldName).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
for _, c := range _columns {
|
||||
if c.Name() == common.DefaultFloatVecFieldName {
|
||||
@ -302,13 +302,13 @@ func TestUpsertAutoID(t *testing.T) {
|
||||
// insertRes pks were deleted
|
||||
expr := fmt.Sprintf("%s <= %d", common.DefaultInt64FieldName, insertRes.IDs.(*column.ColumnInt64).Data()[nb-1])
|
||||
log.Debug("expr", zap.String("expr", expr))
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithOutputFields([]string{common.DefaultFloatVecFieldName}).WithFilter(expr))
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithOutputFields(common.DefaultFloatVecFieldName).WithFilter(expr))
|
||||
common.CheckErr(t, err, true)
|
||||
require.EqualValues(t, 0, resSet.ResultCount)
|
||||
|
||||
exprUpsert := fmt.Sprintf("%s <= %d", common.DefaultInt64FieldName, upsertRes.IDs.(*column.ColumnInt64).Data()[nb-1])
|
||||
log.Debug("expr", zap.String("expr", expr))
|
||||
resSet1, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithOutputFields([]string{common.DefaultFloatVecFieldName}).WithFilter(exprUpsert))
|
||||
resSet1, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithOutputFields(common.DefaultFloatVecFieldName).WithFilter(exprUpsert))
|
||||
common.CheckErr(t, err, true)
|
||||
common.EqualColumn(t, vecColumn, resSet1.GetColumn(common.DefaultFloatVecFieldName))
|
||||
|
||||
@ -320,7 +320,7 @@ func TestUpsertAutoID(t *testing.T) {
|
||||
|
||||
// query and verify upsert result
|
||||
upsertPks := upsertRes.IDs.(*column.ColumnInt64).Data()
|
||||
resSet, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithOutputFields([]string{common.DefaultFloatVecFieldName}).
|
||||
resSet, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithConsistencyLevel(entity.ClStrong).WithOutputFields(common.DefaultFloatVecFieldName).
|
||||
WithFilter(fmt.Sprintf("%d <= %s", upsertPks[0], common.DefaultInt64FieldName)))
|
||||
common.CheckErr(t, err, true)
|
||||
common.EqualColumn(t, vecColumn, resSet.GetColumn(common.DefaultFloatVecFieldName))
|
||||
@ -418,7 +418,7 @@ func TestUpsertDynamicField(t *testing.T) {
|
||||
// verify that dynamic field exists
|
||||
upsertNb := 10
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(fmt.Sprintf("%s < %d", common.DefaultDynamicNumberField, upsertNb)).
|
||||
WithOutputFields([]string{common.DefaultDynamicFieldName}).WithConsistencyLevel(entity.ClStrong))
|
||||
WithOutputFields(common.DefaultDynamicFieldName).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
require.Equal(t, upsertNb, resSet.GetColumn(common.DefaultDynamicFieldName).Len())
|
||||
|
||||
@ -430,7 +430,7 @@ func TestUpsertDynamicField(t *testing.T) {
|
||||
|
||||
// query and gets empty
|
||||
resSet, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(fmt.Sprintf("%s < %d", common.DefaultDynamicNumberField, upsertNb)).
|
||||
WithOutputFields([]string{common.DefaultDynamicFieldName}).WithConsistencyLevel(entity.ClStrong))
|
||||
WithOutputFields(common.DefaultDynamicFieldName).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
require.Equal(t, 0, resSet.GetColumn(common.DefaultDynamicFieldName).Len())
|
||||
|
||||
@ -443,7 +443,7 @@ func TestUpsertDynamicField(t *testing.T) {
|
||||
|
||||
// query and gets dynamic field
|
||||
resSet, err = mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(fmt.Sprintf("%s >= %d", common.DefaultDynamicNumberField, common.DefaultNb)).
|
||||
WithOutputFields([]string{common.DefaultDynamicFieldName}).WithConsistencyLevel(entity.ClStrong))
|
||||
WithOutputFields(common.DefaultDynamicFieldName).WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.EqualColumn(t, hp.MergeColumnsToDynamic(upsertNb, dynamicColumns, common.DefaultDynamicFieldName), resSet.GetColumn(common.DefaultDynamicFieldName))
|
||||
}
|
||||
@ -469,7 +469,7 @@ func TestUpsertWithoutLoading(t *testing.T) {
|
||||
|
||||
// query and verify
|
||||
resSet, err := mc.Query(ctx, client.NewQueryOption(schema.CollectionName).WithFilter(fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, upsertNb)).
|
||||
WithOutputFields([]string{"*"}).WithConsistencyLevel(entity.ClStrong))
|
||||
WithOutputFields("*").WithConsistencyLevel(entity.ClStrong))
|
||||
common.CheckErr(t, err, true)
|
||||
common.CheckQueryResult(t, []column.Column{pkColumn, jsonColumn, vecColumn}, resSet.Fields)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user