From a62118ca33cceff488a854eb23cfe2e24da2bc78 Mon Sep 17 00:00:00 2001 From: ThreadDao Date: Mon, 5 Aug 2024 18:00:16 +0800 Subject: [PATCH] test: update cases for index describe and upsert with autoID (#35191) issue: #33419 --------- Signed-off-by: ThreadDao --- .github/workflows/code-checker.yaml | 1 + .github/workflows/mac.yaml | 1 + tests/go_client/base/milvus_client.go | 63 +++++----- tests/go_client/common/consts.go | 11 ++ tests/go_client/common/response_checker.go | 48 +++++++- tests/go_client/go.mod | 6 +- tests/go_client/go.sum | 8 +- tests/go_client/testcases/collection_test.go | 2 +- tests/go_client/testcases/delete_test.go | 26 ++-- .../go_client/testcases/helper/data_helper.go | 2 +- tests/go_client/testcases/index_test.go | 114 +++++++++--------- tests/go_client/testcases/insert_test.go | 2 +- tests/go_client/testcases/partition_test.go | 2 +- tests/go_client/testcases/query_test.go | 20 +-- tests/go_client/testcases/search_test.go | 50 ++++---- tests/go_client/testcases/upsert_test.go | 64 +++++++--- 16 files changed, 255 insertions(+), 165 deletions(-) diff --git a/.github/workflows/code-checker.yaml b/.github/workflows/code-checker.yaml index a9805bb4bdb4c..3e8fa1001f5dc 100644 --- a/.github/workflows/code-checker.yaml +++ b/.github/workflows/code-checker.yaml @@ -16,6 +16,7 @@ on: - 'cmd/**' - 'build/**' - 'tests/integration/**' + - 'tests/go_client/**' - '.github/workflows/code-checker.yaml' - '.env' - docker-compose.yml diff --git a/.github/workflows/mac.yaml b/.github/workflows/mac.yaml index 13ea053023690..d66ac2f4f06d2 100644 --- a/.github/workflows/mac.yaml +++ b/.github/workflows/mac.yaml @@ -15,6 +15,7 @@ on: - 'cmd/**' - 'build/**' - 'tests/integration/**' + - 'tests/go_client/**' - '.github/workflows/mac.yaml' - '.env' - docker-compose.yml diff --git a/tests/go_client/base/milvus_client.go b/tests/go_client/base/milvus_client.go index fd1b29f8d91c0..0eb6ed42057a2 100644 --- a/tests/go_client/base/milvus_client.go +++ b/tests/go_client/base/milvus_client.go @@ -9,9 +9,8 @@ import ( "go.uber.org/zap" "google.golang.org/grpc" - clientv2 "github.com/milvus-io/milvus/client/v2" + "github.com/milvus-io/milvus/client/v2" "github.com/milvus-io/milvus/client/v2/entity" - "github.com/milvus-io/milvus/client/v2/index" "github.com/milvus-io/milvus/pkg/log" ) @@ -58,12 +57,12 @@ func LoggingUnaryInterceptor() grpc.UnaryClientInterceptor { } type MilvusClient struct { - mClient *clientv2.Client + mClient *client.Client } -func NewMilvusClient(ctx context.Context, cfg *clientv2.ClientConfig) (*MilvusClient, error) { +func NewMilvusClient(ctx context.Context, cfg *client.ClientConfig) (*MilvusClient, error) { cfg.DialOptions = append(cfg.DialOptions, grpc.WithUnaryInterceptor(LoggingUnaryInterceptor())) - mClient, err := clientv2.New(ctx, cfg) + mClient, err := client.New(ctx, cfg) return &MilvusClient{ mClient, }, err @@ -77,25 +76,25 @@ func (mc *MilvusClient) Close(ctx context.Context) error { // -- database -- // UsingDatabase list all database in milvus cluster. -func (mc *MilvusClient) UsingDatabase(ctx context.Context, option clientv2.UsingDatabaseOption) error { +func (mc *MilvusClient) UsingDatabase(ctx context.Context, option client.UsingDatabaseOption) error { err := mc.mClient.UsingDatabase(ctx, option) return err } // ListDatabases list all database in milvus cluster. -func (mc *MilvusClient) ListDatabases(ctx context.Context, option clientv2.ListDatabaseOption, callOptions ...grpc.CallOption) ([]string, error) { +func (mc *MilvusClient) ListDatabases(ctx context.Context, option client.ListDatabaseOption, callOptions ...grpc.CallOption) ([]string, error) { databaseNames, err := mc.mClient.ListDatabase(ctx, option, callOptions...) return databaseNames, err } // CreateDatabase create database with the given name. -func (mc *MilvusClient) CreateDatabase(ctx context.Context, option clientv2.CreateDatabaseOption, callOptions ...grpc.CallOption) error { +func (mc *MilvusClient) CreateDatabase(ctx context.Context, option client.CreateDatabaseOption, callOptions ...grpc.CallOption) error { err := mc.mClient.CreateDatabase(ctx, option, callOptions...) return err } // DropDatabase drop database with the given db name. -func (mc *MilvusClient) DropDatabase(ctx context.Context, option clientv2.DropDatabaseOption, callOptions ...grpc.CallOption) error { +func (mc *MilvusClient) DropDatabase(ctx context.Context, option client.DropDatabaseOption, callOptions ...grpc.CallOption) error { err := mc.mClient.DropDatabase(ctx, option, callOptions...) return err } @@ -103,31 +102,31 @@ func (mc *MilvusClient) DropDatabase(ctx context.Context, option clientv2.DropDa // -- collection -- // CreateCollection Create Collection -func (mc *MilvusClient) CreateCollection(ctx context.Context, option clientv2.CreateCollectionOption, callOptions ...grpc.CallOption) error { +func (mc *MilvusClient) CreateCollection(ctx context.Context, option client.CreateCollectionOption, callOptions ...grpc.CallOption) error { err := mc.mClient.CreateCollection(ctx, option, callOptions...) return err } // ListCollections Create Collection -func (mc *MilvusClient) ListCollections(ctx context.Context, option clientv2.ListCollectionOption, callOptions ...grpc.CallOption) ([]string, error) { +func (mc *MilvusClient) ListCollections(ctx context.Context, option client.ListCollectionOption, callOptions ...grpc.CallOption) ([]string, error) { collectionNames, err := mc.mClient.ListCollections(ctx, option, callOptions...) return collectionNames, err } // DescribeCollection Describe collection -func (mc *MilvusClient) DescribeCollection(ctx context.Context, option clientv2.DescribeCollectionOption, callOptions ...grpc.CallOption) (*entity.Collection, error) { +func (mc *MilvusClient) DescribeCollection(ctx context.Context, option client.DescribeCollectionOption, callOptions ...grpc.CallOption) (*entity.Collection, error) { collection, err := mc.mClient.DescribeCollection(ctx, option, callOptions...) return collection, err } // HasCollection Has collection -func (mc *MilvusClient) HasCollection(ctx context.Context, option clientv2.HasCollectionOption, callOptions ...grpc.CallOption) (bool, error) { +func (mc *MilvusClient) HasCollection(ctx context.Context, option client.HasCollectionOption, callOptions ...grpc.CallOption) (bool, error) { has, err := mc.mClient.HasCollection(ctx, option, callOptions...) return has, err } // DropCollection Drop Collection -func (mc *MilvusClient) DropCollection(ctx context.Context, option clientv2.DropCollectionOption, callOptions ...grpc.CallOption) error { +func (mc *MilvusClient) DropCollection(ctx context.Context, option client.DropCollectionOption, callOptions ...grpc.CallOption) error { err := mc.mClient.DropCollection(ctx, option, callOptions...) return err } @@ -135,31 +134,31 @@ func (mc *MilvusClient) DropCollection(ctx context.Context, option clientv2.Drop // -- partition -- // CreatePartition Create Partition -func (mc *MilvusClient) CreatePartition(ctx context.Context, option clientv2.CreatePartitionOption, callOptions ...grpc.CallOption) error { +func (mc *MilvusClient) CreatePartition(ctx context.Context, option client.CreatePartitionOption, callOptions ...grpc.CallOption) error { err := mc.mClient.CreatePartition(ctx, option, callOptions...) return err } // DropPartition Drop Partition -func (mc *MilvusClient) DropPartition(ctx context.Context, option clientv2.DropPartitionOption, callOptions ...grpc.CallOption) error { +func (mc *MilvusClient) DropPartition(ctx context.Context, option client.DropPartitionOption, callOptions ...grpc.CallOption) error { err := mc.mClient.DropPartition(ctx, option, callOptions...) return err } // HasPartition Has Partition -func (mc *MilvusClient) HasPartition(ctx context.Context, option clientv2.HasPartitionOption, callOptions ...grpc.CallOption) (bool, error) { +func (mc *MilvusClient) HasPartition(ctx context.Context, option client.HasPartitionOption, callOptions ...grpc.CallOption) (bool, error) { has, err := mc.mClient.HasPartition(ctx, option, callOptions...) return has, err } // ListPartitions List Partitions -func (mc *MilvusClient) ListPartitions(ctx context.Context, option clientv2.ListPartitionsOption, callOptions ...grpc.CallOption) ([]string, error) { +func (mc *MilvusClient) ListPartitions(ctx context.Context, option client.ListPartitionsOption, callOptions ...grpc.CallOption) ([]string, error) { partitionNames, err := mc.mClient.ListPartitions(ctx, option, callOptions...) return partitionNames, err } // LoadPartitions Load Partitions into memory -func (mc *MilvusClient) LoadPartitions(ctx context.Context, option clientv2.LoadPartitionsOption, callOptions ...grpc.CallOption) (clientv2.LoadTask, error) { +func (mc *MilvusClient) LoadPartitions(ctx context.Context, option client.LoadPartitionsOption, callOptions ...grpc.CallOption) (client.LoadTask, error) { loadTask, err := mc.mClient.LoadPartitions(ctx, option, callOptions...) return loadTask, err } @@ -167,25 +166,25 @@ func (mc *MilvusClient) LoadPartitions(ctx context.Context, option clientv2.Load // -- index -- // CreateIndex Create Index -func (mc *MilvusClient) CreateIndex(ctx context.Context, option clientv2.CreateIndexOption, callOptions ...grpc.CallOption) (*clientv2.CreateIndexTask, error) { +func (mc *MilvusClient) CreateIndex(ctx context.Context, option client.CreateIndexOption, callOptions ...grpc.CallOption) (*client.CreateIndexTask, error) { createIndexTask, err := mc.mClient.CreateIndex(ctx, option, callOptions...) return createIndexTask, err } // ListIndexes List Indexes -func (mc *MilvusClient) ListIndexes(ctx context.Context, option clientv2.ListIndexOption, callOptions ...grpc.CallOption) ([]string, error) { +func (mc *MilvusClient) ListIndexes(ctx context.Context, option client.ListIndexOption, callOptions ...grpc.CallOption) ([]string, error) { indexes, err := mc.mClient.ListIndexes(ctx, option, callOptions...) return indexes, err } // DescribeIndex Describe Index -func (mc *MilvusClient) DescribeIndex(ctx context.Context, option clientv2.DescribeIndexOption, callOptions ...grpc.CallOption) (index.Index, error) { - idx, err := mc.mClient.DescribeIndex(ctx, option, callOptions...) - return idx, err +func (mc *MilvusClient) DescribeIndex(ctx context.Context, option client.DescribeIndexOption, callOptions ...grpc.CallOption) (client.IndexDescription, error) { + idxDesc, err := mc.mClient.DescribeIndex(ctx, option, callOptions...) + return idxDesc, err } // DropIndex Drop Index -func (mc *MilvusClient) DropIndex(ctx context.Context, option clientv2.DropIndexOption, callOptions ...grpc.CallOption) error { +func (mc *MilvusClient) DropIndex(ctx context.Context, option client.DropIndexOption, callOptions ...grpc.CallOption) error { err := mc.mClient.DropIndex(ctx, option, callOptions...) return err } @@ -193,7 +192,7 @@ func (mc *MilvusClient) DropIndex(ctx context.Context, option clientv2.DropIndex // -- write -- // Insert insert data -func (mc *MilvusClient) Insert(ctx context.Context, option clientv2.InsertOption, callOptions ...grpc.CallOption) (clientv2.InsertResult, error) { +func (mc *MilvusClient) Insert(ctx context.Context, option client.InsertOption, callOptions ...grpc.CallOption) (client.InsertResult, error) { insertRes, err := mc.mClient.Insert(ctx, option, callOptions...) if err == nil { log.Info("Insert", zap.Any("result", insertRes)) @@ -202,19 +201,19 @@ func (mc *MilvusClient) Insert(ctx context.Context, option clientv2.InsertOption } // Flush flush data -func (mc *MilvusClient) Flush(ctx context.Context, option clientv2.FlushOption, callOptions ...grpc.CallOption) (*clientv2.FlushTask, error) { +func (mc *MilvusClient) Flush(ctx context.Context, option client.FlushOption, callOptions ...grpc.CallOption) (*client.FlushTask, error) { flushTask, err := mc.mClient.Flush(ctx, option, callOptions...) return flushTask, err } // Delete deletes data -func (mc *MilvusClient) Delete(ctx context.Context, option clientv2.DeleteOption, callOptions ...grpc.CallOption) (clientv2.DeleteResult, error) { +func (mc *MilvusClient) Delete(ctx context.Context, option client.DeleteOption, callOptions ...grpc.CallOption) (client.DeleteResult, error) { deleteRes, err := mc.mClient.Delete(ctx, option, callOptions...) return deleteRes, err } // Upsert upsert data -func (mc *MilvusClient) Upsert(ctx context.Context, option clientv2.UpsertOption, callOptions ...grpc.CallOption) (clientv2.UpsertResult, error) { +func (mc *MilvusClient) Upsert(ctx context.Context, option client.UpsertOption, callOptions ...grpc.CallOption) (client.UpsertResult, error) { upsertRes, err := mc.mClient.Upsert(ctx, option, callOptions...) return upsertRes, err } @@ -222,19 +221,19 @@ func (mc *MilvusClient) Upsert(ctx context.Context, option clientv2.UpsertOption // -- read -- // LoadCollection Load Collection -func (mc *MilvusClient) LoadCollection(ctx context.Context, option clientv2.LoadCollectionOption, callOptions ...grpc.CallOption) (clientv2.LoadTask, error) { +func (mc *MilvusClient) LoadCollection(ctx context.Context, option client.LoadCollectionOption, callOptions ...grpc.CallOption) (client.LoadTask, error) { loadTask, err := mc.mClient.LoadCollection(ctx, option, callOptions...) return loadTask, err } // Search search from collection -func (mc *MilvusClient) Search(ctx context.Context, option clientv2.SearchOption, callOptions ...grpc.CallOption) ([]clientv2.ResultSet, error) { +func (mc *MilvusClient) Search(ctx context.Context, option client.SearchOption, callOptions ...grpc.CallOption) ([]client.ResultSet, error) { resultSets, err := mc.mClient.Search(ctx, option, callOptions...) return resultSets, err } // Query query from collection -func (mc *MilvusClient) Query(ctx context.Context, option clientv2.QueryOption, callOptions ...grpc.CallOption) (clientv2.ResultSet, error) { +func (mc *MilvusClient) Query(ctx context.Context, option client.QueryOption, callOptions ...grpc.CallOption) (client.ResultSet, error) { resultSet, err := mc.mClient.Query(ctx, option, callOptions...) return resultSet, err } diff --git a/tests/go_client/common/consts.go b/tests/go_client/common/consts.go index d72dec2971be8..91a6df94fb219 100644 --- a/tests/go_client/common/consts.go +++ b/tests/go_client/common/consts.go @@ -1,5 +1,7 @@ package common +import "github.com/milvus-io/milvus/client/v2/index" + // cost default field name const ( DefaultInt8FieldName = "int8" @@ -65,3 +67,12 @@ const ( MaxVectorFieldNum = 4 MaxShardNum = 16 ) + +const ( + IndexStateIndexStateNone index.IndexState = 0 + IndexStateUnissued index.IndexState = 1 + IndexStateInProgress index.IndexState = 2 + IndexStateFinished index.IndexState = 3 + IndexStateFailed index.IndexState = 4 + IndexStateRetry index.IndexState = 5 +) diff --git a/tests/go_client/common/response_checker.go b/tests/go_client/common/response_checker.go index 4c983e8d5a725..96910e68ef59d 100644 --- a/tests/go_client/common/response_checker.go +++ b/tests/go_client/common/response_checker.go @@ -9,9 +9,10 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" - clientv2 "github.com/milvus-io/milvus/client/v2" + "github.com/milvus-io/milvus/client/v2" "github.com/milvus-io/milvus/client/v2/column" "github.com/milvus-io/milvus/client/v2/entity" + "github.com/milvus-io/milvus/client/v2/index" "github.com/milvus-io/milvus/pkg/log" ) @@ -123,7 +124,7 @@ func EqualArrayColumn(t *testing.T, columnA column.Column, columnB column.Column } // CheckInsertResult check insert result, ids len (insert count), ids data (pks, but no auto ids) -func CheckInsertResult(t *testing.T, expIds column.Column, insertRes clientv2.InsertResult) { +func CheckInsertResult(t *testing.T, expIds column.Column, insertRes client.InsertResult) { require.Equal(t, expIds.Len(), insertRes.IDs.Len()) require.Equal(t, expIds.Len(), int(insertRes.InsertCount)) actualIds := insertRes.IDs @@ -149,7 +150,7 @@ func CheckOutputFields(t *testing.T, expFields []string, actualColumns []column. } // CheckSearchResult check search result, check nq, topk, ids, score -func CheckSearchResult(t *testing.T, actualSearchResults []clientv2.ResultSet, expNq int, expTopK int) { +func CheckSearchResult(t *testing.T, actualSearchResults []client.ResultSet, expNq int, expTopK int) { require.Equal(t, len(actualSearchResults), expNq) require.Len(t, actualSearchResults, expNq) for _, actualSearchResult := range actualSearchResults { @@ -176,3 +177,44 @@ func CheckQueryResult(t *testing.T, expColumns []column.Column, actualColumns [] } } } + +// GenColumnDataOption -- create column data -- +type checkIndexOpt struct { + state index.IndexState + pendingIndexRows int64 + totalRows int64 + indexedRows int64 +} + +func TNewCheckIndexOpt(totalRows int64) *checkIndexOpt { + return &checkIndexOpt{ + state: IndexStateFinished, + totalRows: totalRows, + pendingIndexRows: 0, + indexedRows: totalRows, + } +} + +func (opt *checkIndexOpt) TWithIndexState(state index.IndexState) *checkIndexOpt { + opt.state = state + return opt +} + +func (opt *checkIndexOpt) TWithIndexRows(totalRows int64, indexedRows int64, pendingIndexRows int64) *checkIndexOpt { + opt.totalRows = totalRows + opt.indexedRows = indexedRows + opt.pendingIndexRows = pendingIndexRows + return opt +} + +func CheckIndex(t *testing.T, actualIdxDesc client.IndexDescription, idx index.Index, opt *checkIndexOpt) { + require.EqualValuesf(t, idx, actualIdxDesc.Index, "Actual index is not same with expected index") + require.Equal(t, actualIdxDesc.TotalRows, actualIdxDesc.PendingIndexRows+actualIdxDesc.IndexedRows) + if opt != nil { + require.Equal(t, opt.totalRows, opt.pendingIndexRows+opt.indexedRows) + require.Equal(t, opt.state, actualIdxDesc.State) + require.Equal(t, opt.totalRows, actualIdxDesc.TotalRows) + require.Equal(t, opt.indexedRows, actualIdxDesc.IndexedRows) + require.Equal(t, opt.pendingIndexRows, actualIdxDesc.PendingIndexRows) + } +} diff --git a/tests/go_client/go.mod b/tests/go_client/go.mod index 42947e9170cbf..8c80446357418 100644 --- a/tests/go_client/go.mod +++ b/tests/go_client/go.mod @@ -5,7 +5,7 @@ go 1.21 toolchain go1.21.11 require ( - github.com/milvus-io/milvus/client/v2 v2.0.0-20240729131949-a8a4779749de + github.com/milvus-io/milvus/client/v2 v2.0.0-20240805024817-4b553b0333f4 github.com/milvus-io/milvus/pkg v0.0.2-0.20240801085213-a642a26ed4c6 github.com/quasilyte/go-ruleguard/dsl v0.3.22 github.com/stretchr/testify v1.9.0 @@ -14,6 +14,8 @@ require ( google.golang.org/grpc v1.65.0 ) +replace github.com/milvus-io/milvus/client/v2 v2.0.0-20240805024817-4b553b0333f4 => ../../../milvus/client + require ( github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver/v4 v4.0.0 // indirect @@ -114,7 +116,7 @@ require ( golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect - google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect google.golang.org/protobuf v1.34.2 // indirect diff --git a/tests/go_client/go.sum b/tests/go_client/go.sum index 45fea20bea8e8..c972fe7869271 100644 --- a/tests/go_client/go.sum +++ b/tests/go_client/go.sum @@ -390,8 +390,8 @@ github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/le github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240717062137-3ffb1db01632 h1:CXig0DNtUsCLzchCFe3PR2KgOdobbz9gK2nSV7195PM= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240717062137-3ffb1db01632/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs= -github.com/milvus-io/milvus/client/v2 v2.0.0-20240729131949-a8a4779749de h1:GtxjVQ5VfGNf/bEN/K4zKCnVXtq7PkSsniWVlAF7GlI= -github.com/milvus-io/milvus/client/v2 v2.0.0-20240729131949-a8a4779749de/go.mod h1:CGX8NwpP5T7tSDzYOBJDgyW1PK/vNixosoR8r5BMqMA= +github.com/milvus-io/milvus/client/v2 v2.0.0-20240805024817-4b553b0333f4 h1:0VEsc69duq3NMNRYWq0qtJDN6HSj13USju1ZdlmvUo0= +github.com/milvus-io/milvus/client/v2 v2.0.0-20240805024817-4b553b0333f4/go.mod h1:p2fU+bPgEy+OBYUvhE1+ABEp3KaFQyY586DSs6iEDHk= github.com/milvus-io/milvus/pkg v0.0.2-0.20240801085213-a642a26ed4c6 h1:dotu470D/DkctdLHsTCCmuvAD3h5C8gkFhMxb0Zlu7A= github.com/milvus-io/milvus/pkg v0.0.2-0.20240801085213-a642a26ed4c6/go.mod h1:tdeEcpeaAcrIJgrr6LVzu7SYl9zn18dNKZwPmCUb0Io= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -1014,8 +1014,8 @@ google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= -google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY= -google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4= +google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ= +google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw= google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU= google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf h1:liao9UHurZLtiEwBgT9LMOnKYsHze6eA6w1KQCMVN2Q= diff --git a/tests/go_client/testcases/collection_test.go b/tests/go_client/testcases/collection_test.go index 98dba74bf9779..1f53798cb5caa 100644 --- a/tests/go_client/testcases/collection_test.go +++ b/tests/go_client/testcases/collection_test.go @@ -937,7 +937,7 @@ func TestCreateCollectionInvalid(t *testing.T) { } vecField := entity.NewField().WithName("vec").WithDataType(entity.FieldTypeFloatVector).WithDim(8) mSchemaErrs := []mSchemaErr{ - {schema: nil, errMsg: "duplicated field name"}, + {schema: nil, errMsg: "schema does not contain vector field"}, {schema: entity.NewSchema().WithField(vecField), errMsg: "collection name should not be empty"}, // no collection name {schema: entity.NewSchema().WithName("aaa").WithField(vecField), errMsg: "primary key is not specified"}, // no pk field {schema: entity.NewSchema().WithName("aaa").WithField(vecField).WithField(entity.NewField()), errMsg: "primary key is not specified"}, diff --git a/tests/go_client/testcases/delete_test.go b/tests/go_client/testcases/delete_test.go index 6be0a8f4a414a..4db1a57a7c0d4 100644 --- a/tests/go_client/testcases/delete_test.go +++ b/tests/go_client/testcases/delete_test.go @@ -24,7 +24,7 @@ func TestDelete(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load collection @@ -60,7 +60,7 @@ func TestDeleteVarcharPks(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load collection @@ -138,7 +138,7 @@ func TestDeleteComplexExprWithoutLoad(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) idsPk := []int64{0, 1, 2, 3, 4} @@ -201,7 +201,7 @@ func TestDeleteVarcharEmptyIds(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load collection @@ -305,8 +305,8 @@ func TestDeleteDefaultPartitionName(t *testing.T) { common.CheckErr(t, err, true) // insert [0, 3000) into default, insert [3000, 6000) into p1 - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load @@ -343,8 +343,8 @@ func TestDeleteEmptyPartitionName(t *testing.T) { common.CheckErr(t, err, true) // insert [0, 3000) into default, insert [3000, 6000) into p1 - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load @@ -381,8 +381,8 @@ func TestDeletePartitionName(t *testing.T) { common.CheckErr(t, err, true) // insert [0, 3000) into default, insert [3000, 6000) into parName - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load @@ -485,7 +485,7 @@ func TestDeleteComplexExpr(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert [0, 3000) into default - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption().TWithMaxCapacity(common.TestCapacity)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithMaxCapacity(common.TestCapacity)) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load @@ -514,7 +514,7 @@ func TestDeleteInvalidExpr(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert [0, 3000) into default - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption().TWithMaxCapacity(common.TestCapacity)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithMaxCapacity(common.TestCapacity)) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load @@ -537,7 +537,7 @@ func TestDeleteDuplicatedPks(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption().TWithIsDynamic(true), hp.TNewSchemaOption()) // insert [0, 3000) into default - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption().TWithMaxCapacity(common.TestCapacity)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithMaxCapacity(common.TestCapacity)) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index and load diff --git a/tests/go_client/testcases/helper/data_helper.go b/tests/go_client/testcases/helper/data_helper.go index 4fa11bb70838c..c6ed87ba383a6 100644 --- a/tests/go_client/testcases/helper/data_helper.go +++ b/tests/go_client/testcases/helper/data_helper.go @@ -20,7 +20,7 @@ type InsertParams struct { IsRows bool } -func NewInsertParams(schema *entity.Schema, nb int) *InsertParams { +func NewInsertParams(schema *entity.Schema) *InsertParams { return &InsertParams{ Schema: schema, } diff --git a/tests/go_client/testcases/index_test.go b/tests/go_client/testcases/index_test.go index 8e23c7743a0b9..309bc22578d95 100644 --- a/tests/go_client/testcases/index_test.go +++ b/tests/go_client/testcases/index_test.go @@ -25,7 +25,7 @@ func TestIndexVectorDefault(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -40,7 +40,7 @@ func TestIndexVectorDefault(t *testing.T) { descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, fieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, index.NewGenericIndex(fieldName, idx.Params()), descIdx) + common.CheckIndex(t, descIdx, index.NewGenericIndex(fieldName, idx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) // drop index err = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, descIdx.Name())) @@ -58,7 +58,7 @@ func TestIndexVectorIP(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -74,7 +74,7 @@ func TestIndexVectorIP(t *testing.T) { expIdx := index.NewGenericIndex(fieldName, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, fieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, expIdx, descIdx) + common.CheckIndex(t, descIdx, expIdx, common.TNewCheckIndexOpt(common.DefaultNb)) // drop index err = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, expIdx.Name())) @@ -92,7 +92,7 @@ func TestIndexVectorCosine(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -108,7 +108,7 @@ func TestIndexVectorCosine(t *testing.T) { expIdx := index.NewGenericIndex(fieldName, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, fieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, expIdx, descIdx) + common.CheckIndex(t, descIdx, expIdx, common.TNewCheckIndexOpt(common.DefaultNb)) // drop index err = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, expIdx.Name())) @@ -126,7 +126,7 @@ func TestIndexAutoFloatVector(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -146,7 +146,7 @@ func TestIndexAutoFloatVector(t *testing.T) { expIdx := index.NewGenericIndex(common.DefaultFloatVecFieldName, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultFloatVecFieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, expIdx, descIdx) + common.CheckIndex(t, descIdx, expIdx, common.TNewCheckIndexOpt(common.DefaultNb)) // drop index err = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, expIdx.Name())) @@ -163,7 +163,7 @@ func TestIndexAutoBinaryVector(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -187,7 +187,7 @@ func TestIndexAutoBinaryVector(t *testing.T) { expIdx := index.NewGenericIndex(common.DefaultBinaryVecFieldName, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultBinaryVecFieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, expIdx, descIdx) + common.CheckIndex(t, descIdx, expIdx, common.TNewCheckIndexOpt(common.DefaultNb)) // drop index err = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, expIdx.Name())) @@ -204,7 +204,7 @@ func TestIndexAutoSparseVector(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -225,7 +225,7 @@ func TestIndexAutoSparseVector(t *testing.T) { expIdx := index.NewGenericIndex(common.DefaultSparseVecFieldName, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultSparseVecFieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, expIdx, descIdx) + common.CheckIndex(t, descIdx, expIdx, common.TNewCheckIndexOpt(common.DefaultNb)) // drop index err = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, expIdx.Name())) @@ -241,17 +241,17 @@ func TestCreateAutoIndexAllFields(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) var expFields []string var idx index.Index for _, field := range schema.Fields { - if field.DataType == entity.FieldTypeArray || field.DataType == entity.FieldTypeJSON { + if field.DataType == entity.FieldTypeJSON { idx = index.NewAutoIndex(entity.IP) _, err := mc.CreateIndex(ctx, client.NewCreateIndexOption(schema.CollectionName, field.Name, idx)) - common.CheckErr(t, err, false, fmt.Sprintf("create auto index on %s field is not supported", field.DataType)) + common.CheckErr(t, err, false, fmt.Sprintf("create auto index on type:%s is not supported", field.DataType)) } else { if field.DataType == entity.FieldTypeBinaryVector { idx = index.NewAutoIndex(entity.JACCARD) @@ -266,7 +266,7 @@ func TestCreateAutoIndexAllFields(t *testing.T) { // describe index descIdx, descErr := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, field.Name)) common.CheckErr(t, descErr, true) - require.EqualValues(t, index.NewGenericIndex(field.Name, idx.Params()), descIdx) + common.CheckIndex(t, descIdx, index.NewGenericIndex(field.Name, idx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) } expFields = append(expFields, field.Name) } @@ -287,7 +287,7 @@ func TestIndexBinaryFlat(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -302,7 +302,7 @@ func TestIndexBinaryFlat(t *testing.T) { expIdx := index.NewGenericIndex(common.DefaultBinaryVecFieldName, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultBinaryVecFieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, expIdx, descIdx) + common.CheckIndex(t, descIdx, expIdx, common.TNewCheckIndexOpt(common.DefaultNb)) // drop index err = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, expIdx.Name())) @@ -318,7 +318,7 @@ func TestIndexBinaryIvfFlat(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -333,7 +333,7 @@ func TestIndexBinaryIvfFlat(t *testing.T) { expIdx := index.NewGenericIndex(common.DefaultBinaryVecFieldName, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultBinaryVecFieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, expIdx, descIdx) + common.CheckIndex(t, descIdx, expIdx, common.TNewCheckIndexOpt(common.DefaultNb)) // drop index err = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, expIdx.Name())) @@ -350,7 +350,7 @@ func TestCreateBinaryIndexNotSupportedMetricType(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -415,7 +415,7 @@ func TestCreateTrieScalarIndex(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -433,7 +433,7 @@ func TestCreateTrieScalarIndex(t *testing.T) { expIndex := index.NewGenericIndex(field.Name, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, field.Name)) common.CheckErr(t, err, true) - require.EqualValues(t, expIndex, descIdx) + common.CheckIndex(t, descIdx, expIndex, common.TNewCheckIndexOpt(common.DefaultNb)) } else { _, err := mc.CreateIndex(ctx, client.NewCreateIndexOption(schema.CollectionName, field.Name, idx)) common.CheckErr(t, err, false, "TRIE are only supported on varchar field") @@ -451,7 +451,7 @@ func TestCreateSortedScalarIndex(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) @@ -474,7 +474,7 @@ func TestCreateSortedScalarIndex(t *testing.T) { expIndex := index.NewGenericIndex(field.Name, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, field.Name)) common.CheckErr(t, err, true) - require.EqualValues(t, expIndex, descIdx) + common.CheckIndex(t, descIdx, expIndex, common.TNewCheckIndexOpt(common.DefaultNb)) } } } @@ -501,7 +501,7 @@ func TestCreateInvertedScalarIndex(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) @@ -518,7 +518,7 @@ func TestCreateInvertedScalarIndex(t *testing.T) { // describe index expIndex := index.NewGenericIndex(field.Name, idx.Params()) _index, _ := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, field.Name)) - require.EqualValues(t, expIndex, _index) + common.CheckIndex(t, _index, expIndex, common.TNewCheckIndexOpt(common.DefaultNb)) } } // load -> search and output all fields @@ -544,7 +544,7 @@ func TestCreateScalarIndexVectorField(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -568,7 +568,7 @@ func TestCreateIndexWithOtherFieldName(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -583,7 +583,7 @@ func TestCreateIndexWithOtherFieldName(t *testing.T) { expIndex := index.NewGenericIndex(common.DefaultBinaryVecFieldName, idx.Params()) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultBinaryVecFieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, expIndex, descIdx) + common.CheckIndex(t, descIdx, expIndex, common.TNewCheckIndexOpt(common.DefaultNb)) // create index in binary field with default name idxBinary := index.NewBinFlatIndex(entity.JACCARD) @@ -600,7 +600,7 @@ func TestCreateIndexJsonField(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -634,7 +634,7 @@ func TestCreateUnsupportedIndexArrayField(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) type scalarIndexError struct { @@ -672,7 +672,7 @@ func TestCreateInvertedIndexArrayField(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) @@ -710,7 +710,7 @@ func TestCreateIndexWithoutName(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -725,7 +725,7 @@ func TestCreateIndexWithoutName(t *testing.T) { idxDesc, _ := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultFloatVecFieldName)) expIndex := index.NewGenericIndex(common.DefaultFloatVecFieldName, idx.Params()) require.Equal(t, common.DefaultFloatVecFieldName, idxDesc.Name()) - require.EqualValues(t, expIndex, idxDesc) + common.CheckIndex(t, idxDesc, expIndex, common.TNewCheckIndexOpt(common.DefaultNb)) } // test create index on same field twice @@ -737,20 +737,21 @@ func TestCreateIndexDup(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) // index dup idxHnsw := index.NewHNSWIndex(entity.L2, 8, 96) idxIvfSq8 := index.NewIvfSQ8Index(entity.L2, 128) - _, err := mc.CreateIndex(ctx, client.NewCreateIndexOption(schema.CollectionName, common.DefaultFloatVecFieldName, idxHnsw)) + idxTask, err := mc.CreateIndex(ctx, client.NewCreateIndexOption(schema.CollectionName, common.DefaultFloatVecFieldName, idxHnsw)) common.CheckErr(t, err, true) + idxTask.Await(ctx) // describe index _index, _ := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultFloatVecFieldName)) expIndex := index.NewGenericIndex(common.DefaultFloatVecFieldName, idxHnsw.Params()) - require.EqualValues(t, expIndex, _index) + common.CheckIndex(t, _index, expIndex, common.TNewCheckIndexOpt(common.DefaultNb)) _, err = mc.CreateIndex(ctx, client.NewCreateIndexOption(schema.CollectionName, common.DefaultFloatVecFieldName, idxIvfSq8)) common.CheckErr(t, err, false, "CreateIndex failed: at most one distinct index is allowed per field") @@ -769,7 +770,7 @@ func TestCreateIndexSparseVectorGeneric(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption().TWithSparseMaxLen(100)) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -781,7 +782,7 @@ func TestCreateIndexSparseVectorGeneric(t *testing.T) { descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultSparseVecFieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, index.NewGenericIndex(common.DefaultSparseVecFieldName, idx.Params()), descIdx) + common.CheckIndex(t, descIdx, index.NewGenericIndex(common.DefaultSparseVecFieldName, idx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) } } @@ -797,7 +798,7 @@ func TestCreateIndexSparseVector(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption().TWithSparseMaxLen(100)) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -808,7 +809,7 @@ func TestCreateIndexSparseVector(t *testing.T) { common.CheckErr(t, err, true) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, common.DefaultSparseVecFieldName)) common.CheckErr(t, err, true) - require.EqualValues(t, index.NewGenericIndex(common.DefaultSparseVecFieldName, idx.Params()), descIdx) + common.CheckIndex(t, descIdx, index.NewGenericIndex(common.DefaultSparseVecFieldName, idx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) } } @@ -820,7 +821,7 @@ func TestCreateSparseIndexInvalidParams(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption().TWithSparseMaxLen(100)) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -856,7 +857,7 @@ func TestCreateSparseUnsupportedIndex(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption().TWithSparseMaxLen(100)) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -886,7 +887,7 @@ func TestCreateIndexGeneric(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption().TWithSparseMaxLen(100)) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -900,7 +901,7 @@ func TestCreateIndexGeneric(t *testing.T) { descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, field.Name)) common.CheckErr(t, err, true) - require.EqualValues(t, index.NewGenericIndex(field.Name, idx.Params()), descIdx) + common.CheckIndex(t, descIdx, index.NewGenericIndex(field.Name, idx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) } } @@ -1041,7 +1042,7 @@ func TestCreateIndexAsync(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption().TWithSparseMaxLen(100)) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -1063,7 +1064,7 @@ func TestIndexMultiVectorDupName(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -1091,7 +1092,7 @@ func TestDropIndex(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -1110,21 +1111,21 @@ func TestDropIndex(t *testing.T) { // describe index with index name -> ok descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, idxName)) common.CheckErr(t, err, true) - require.EqualValues(t, index.NewGenericIndex(idxName, idx.Params()), descIdx) + common.CheckIndex(t, descIdx, index.NewGenericIndex(idxName, idx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) // drop index with field name errDrop := mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, common.DefaultFloatVecFieldName)) common.CheckErr(t, errDrop, true) descIdx, err = mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, idxName)) common.CheckErr(t, err, true) - require.EqualValues(t, index.NewGenericIndex(idxName, idx.Params()), descIdx) + common.CheckIndex(t, descIdx, index.NewGenericIndex(idxName, idx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) // drop index with index name errDrop = mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, idxName)) common.CheckErr(t, errDrop, true) _idx, errDescribe := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, idxName)) common.CheckErr(t, errDescribe, false, "index not found") - require.Nil(t, _idx) + common.CheckIndex(t, _idx, nil, nil) } func TestDropIndexCreateIndexWithIndexName(t *testing.T) { @@ -1135,7 +1136,7 @@ func TestDropIndexCreateIndexWithIndexName(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) // insert - ip := hp.NewInsertParams(schema, common.DefaultNb) + ip := hp.NewInsertParams(schema) prepare.InsertData(ctx, t, mc, ip, hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -1149,14 +1150,15 @@ func TestDropIndexCreateIndexWithIndexName(t *testing.T) { common.CheckErr(t, err, true) descIdx, err := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, idxName)) common.CheckErr(t, err, true) - require.EqualValues(t, index.NewGenericIndex(idxName, idx.Params()), descIdx) + common.CheckIndex(t, descIdx, index.NewGenericIndex(idxName, idx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) // drop index errDrop := mc.DropIndex(ctx, client.NewDropIndexOption(schema.CollectionName, idxName)) common.CheckErr(t, errDrop, true) _idx, errDescribe := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, idxName)) common.CheckErr(t, errDescribe, false, "index not found") - require.Nil(t, _idx) + common.CheckIndex(t, _idx, nil, common.TNewCheckIndexOpt(0).TWithIndexRows(0, 0, 0). + TWithIndexState(common.IndexStateIndexStateNone)) // create new IP index ipIdx := index.NewHNSWIndex(entity.IP, 8, 96) @@ -1166,5 +1168,5 @@ func TestDropIndexCreateIndexWithIndexName(t *testing.T) { common.CheckErr(t, err, true) descIdx2, err2 := mc.DescribeIndex(ctx, client.NewDescribeIndexOption(schema.CollectionName, idxName)) common.CheckErr(t, err2, true) - require.EqualValues(t, index.NewGenericIndex(idxName, ipIdx.Params()), descIdx2) + common.CheckIndex(t, descIdx2, index.NewGenericIndex(idxName, ipIdx.Params()), common.TNewCheckIndexOpt(common.DefaultNb)) } diff --git a/tests/go_client/testcases/insert_test.go b/tests/go_client/testcases/insert_test.go index d3a6a5afa9c70..284f84b3fdd2e 100644 --- a/tests/go_client/testcases/insert_test.go +++ b/tests/go_client/testcases/insert_test.go @@ -379,7 +379,7 @@ func TestInsertColumnVarcharExceedLen(t *testing.T) { vecColumn := hp.GenColumnData(100, entity.FieldTypeBinaryVector, *hp.TNewDataOption()) _, err := mc.Insert(ctx, client.NewColumnBasedInsertOption(schema.CollectionName, pkColumn, vecColumn)) - common.CheckErr(t, err, false, "the length (12) of 0th VarChar varchar exceeds max length (0)%!(EXTRA int64=10)") + common.CheckErr(t, err, false, "length of varchar field varchar exceeds max length") } // test insert sparse vector diff --git a/tests/go_client/testcases/partition_test.go b/tests/go_client/testcases/partition_test.go index 42b2dabf98237..355469e4f52a6 100644 --- a/tests/go_client/testcases/partition_test.go +++ b/tests/go_client/testcases/partition_test.go @@ -182,7 +182,7 @@ func TestDropPartitionData(t *testing.T) { require.Truef(t, has, "should has partition") // insert data into partition -> query check - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb).TWithPartitionName(parName), hp.TNewDataOption()) + 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})) common.CheckErr(t, errQ, true) count, _ := res.GetColumn(common.QueryCountFieldName).Get(0) diff --git a/tests/go_client/testcases/query_test.go b/tests/go_client/testcases/query_test.go index 91f88e90b8f0a..5ae85d65d5a3e 100644 --- a/tests/go_client/testcases/query_test.go +++ b/tests/go_client/testcases/query_test.go @@ -23,7 +23,7 @@ func TestQueryDefault(t *testing.T) { // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - _, insertRes := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + _, insertRes := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) // flush -> index -> load prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -44,7 +44,7 @@ func TestQueryVarcharPkDefault(t *testing.T) { // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - _, insertRes := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + _, insertRes := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) // flush -> index -> load prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) @@ -105,8 +105,8 @@ func TestQueryPartition(t *testing.T) { common.CheckErr(t, err, true) // insert [0, 3000) into default, insert [3000, 6000) into parName - _, i1Res := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) - _, i2Res := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) + _, i1Res := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) + _, i2Res := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) // flush -> index -> load prepare.FlushData(ctx, t, mc, schema.CollectionName) @@ -173,7 +173,7 @@ func TestQueryOutputFields(t *testing.T) { for _, enableDynamic := range [2]bool{true, false} { // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(enableDynamic)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -448,7 +448,7 @@ func TestQueryJsonDynamicExpr(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -481,7 +481,7 @@ func TestQueryInvalidExpr(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 100), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(100)) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -498,7 +498,7 @@ func TestQueryCountJsonDynamicExpr(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -570,7 +570,7 @@ func TestQueryArrayFieldExpr(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -617,7 +617,7 @@ func TestQueryOutputInvalidOutputFieldCount(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(false)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) diff --git a/tests/go_client/testcases/search_test.go b/tests/go_client/testcases/search_test.go index 530802229bae6..a7db15eae27ab 100644 --- a/tests/go_client/testcases/search_test.go +++ b/tests/go_client/testcases/search_test.go @@ -24,7 +24,7 @@ func TestSearchDefault(t *testing.T) { // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -44,7 +44,7 @@ func TestSearchDefaultGrowing(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) // search vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeBinaryVector) @@ -190,7 +190,7 @@ func TestSearchEmptyOutputFields(t *testing.T) { for _, dynamic := range []bool{true, false} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(dynamic)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 100), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(100)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -220,7 +220,7 @@ func TestSearchNotExistOutputFields(t *testing.T) { for _, enableDynamic := range []bool{false, true} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(enableDynamic)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -262,7 +262,7 @@ func TestSearchOutputAllFields(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -290,7 +290,7 @@ func TestSearchOutputBinaryPk(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -316,7 +316,7 @@ func TestSearchOutputSparse(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -342,7 +342,7 @@ func TestSearchInvalidVectorField(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 500), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -384,7 +384,7 @@ func TestSearchInvalidVectors(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 500), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -460,7 +460,7 @@ func TestSearchNotMatchMetricType(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 500), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema). TWithFieldIndex(map[string]index.Index{common.DefaultFloatVecFieldName: index.NewHNSWIndex(entity.COSINE, 8, 200)})) @@ -477,7 +477,7 @@ func TestSearchInvalidTopK(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 500), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -495,7 +495,7 @@ func TestSearchInvalidOffset(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 500), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -519,7 +519,7 @@ func TestSearchEfHnsw(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 500), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema). TWithFieldIndex(map[string]index.Index{common.DefaultFloatVecFieldName: index.NewHNSWIndex(entity.COSINE, 8, 200)})) @@ -542,7 +542,7 @@ func TestSearchInvalidScannReorderK(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 500), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema).TWithFieldIndex(map[string]index.Index{ common.DefaultFloatVecFieldName: index.NewSCANNIndex(entity.COSINE, 16, true), @@ -588,7 +588,7 @@ func TestSearchExpr(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -620,7 +620,7 @@ func TestSearchInvalidExpr(t *testing.T) { mc := createDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -665,7 +665,7 @@ func TestSearchJsonFieldExpr(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(dynamicField)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -689,7 +689,7 @@ func TestSearchDynamicFieldExpr(t *testing.T) { // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -751,7 +751,7 @@ func TestSearchArrayFieldExpr(t *testing.T) { // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecArray), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -802,7 +802,7 @@ func TestSearchNotExistedExpr(t *testing.T) { for _, isDynamic := range [2]bool{true, false} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(isDynamic)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -828,7 +828,7 @@ func TestSearchMultiVectors(t *testing.T) { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb*2), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(common.DefaultNb*2)) prepare.FlushData(ctx, t, mc, schema.CollectionName) flatIndex := index.NewFlatIndex(entity.L2) binIndex := index.NewGenericIndex(common.DefaultBinaryVecFieldName, map[string]string{"nlist": "64", index.MetricTypeKey: "JACCARD", index.IndexTypeKey: "BIN_IVF_FLAT"}) @@ -895,7 +895,7 @@ func TestSearchSparseVector(t *testing.T) { for _, idx := range []index.Index{idxInverted, idxWand} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb*2), hp.TNewDataOption().TWithSparseMaxLen(128)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithSparseMaxLen(128).TWithNb(common.DefaultNb*2)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema).TWithFieldIndex(map[string]index.Index{common.DefaultSparseVecFieldName: idx})) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -929,7 +929,7 @@ func TestSearchInvalidSparseVector(t *testing.T) { for _, idx := range []index.Index{idxInverted, idxWand} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption().TWithSparseMaxLen(128)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithSparseMaxLen(128)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema).TWithFieldIndex(map[string]index.Index{common.DefaultSparseVecFieldName: idx})) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -964,7 +964,7 @@ func TestSearchSparseVectorPagination(t *testing.T) { for _, idx := range []index.Index{idxInverted, idxWand} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption().TWithSparseMaxLen(128)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithSparseMaxLen(128)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema).TWithFieldIndex(map[string]index.Index{common.DefaultSparseVecFieldName: idx})) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -1002,7 +1002,7 @@ func TestRangeSearchSparseVector(t *testing.T) { TWithEnableDynamicField(true)) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption().TWithSparseMaxLen(128)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithSparseMaxLen(128)) prepare.FlushData(ctx, t, mc, schema.CollectionName) // TODO range search diff --git a/tests/go_client/testcases/upsert_test.go b/tests/go_client/testcases/upsert_test.go index 669781aa647da..a7e59bf84e4cc 100644 --- a/tests/go_client/testcases/upsert_test.go +++ b/tests/go_client/testcases/upsert_test.go @@ -7,10 +7,12 @@ import ( "time" "github.com/stretchr/testify/require" + "go.uber.org/zap" "github.com/milvus-io/milvus/client/v2" "github.com/milvus-io/milvus/client/v2/column" "github.com/milvus-io/milvus/client/v2/entity" + "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/common" hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper" ) @@ -31,7 +33,7 @@ func TestUpsertAllFields(t *testing.T) { // create -> insert [0, 3000) -> flush -> index -> load // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 0), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -100,7 +102,7 @@ func TestUpsertSparse(t *testing.T) { // create -> insert [0, 3000) -> flush -> index -> load // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 0), hp.TNewDataOption().TWithSparseMaxLen(128)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithSparseMaxLen(128).TWithNb(0)) prepare.FlushData(ctx, t, mc, schema.CollectionName) upsertNb := 200 @@ -164,7 +166,7 @@ func TestUpsertVarcharPk(t *testing.T) { // create -> insert [0, 3000) -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -216,8 +218,8 @@ func TestUpsertMultiPartitions(t *testing.T) { common.CheckErr(t, err, true) // insert [0, nb) into default, insert [nb, nb*2) into new - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema).TWithPartitionName(parName), hp.TNewDataOption().TWithStart(common.DefaultNb)) prepare.FlushData(ctx, t, mc, schema.CollectionName) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -248,7 +250,7 @@ func TestUpsertSamePksManyTimes(t *testing.T) { // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) var _columns []column.Column upsertNb := 10 @@ -284,19 +286,49 @@ func TestUpsertAutoID(t *testing.T) { */ ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) mc := createDefaultMilvusClient(ctx, t) + nb := 100 prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption().TWithAutoID(true), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, 100), hp.TNewDataOption()) + prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) + prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) + _, insertRes := prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(nb)) + + // upsert autoID collection with existed pks -> actually delete passed pks and auto generate new pks ? So weired + vecColumn := hp.GenColumnData(nb, entity.FieldTypeFloatVector, *hp.TNewDataOption()) + upsertRes, err := mc.Upsert(ctx, client.NewColumnBasedInsertOption(schema.CollectionName).WithColumns(insertRes.IDs, vecColumn)) + common.CheckErr(t, err, true) + log.Debug("upsertRes", zap.Any("len", upsertRes.IDs.(*column.ColumnInt64).Data())) - // upsert without pks - vecColumn := hp.GenColumnData(100, entity.FieldTypeFloatVector, *hp.TNewDataOption()) - _, err := mc.Upsert(ctx, client.NewColumnBasedInsertOption(schema.CollectionName).WithColumns(vecColumn)) - common.CheckErr(t, err, false, "upsert can not assign primary field data when auto id enabled") + // 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)) + common.CheckErr(t, err, true) + require.EqualValues(t, 0, resSet.ResultCount) - // upsert with pks + 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)) + common.CheckErr(t, err, true) + common.EqualColumn(t, vecColumn, resSet1.GetColumn(common.DefaultFloatVecFieldName)) + + // upsert with not existing pks -> actually auto generate id ?? so weired pkColumn := hp.GenColumnData(100, entity.FieldTypeInt64, *hp.TNewDataOption()) - _, err1 := mc.Upsert(ctx, client.NewColumnBasedInsertOption(schema.CollectionName).WithColumns(pkColumn, vecColumn)) - common.CheckErr(t, err1, false, "upsert can not assign primary field data when auto id enabled") + upsertRes, err1 := mc.Upsert(ctx, client.NewColumnBasedInsertOption(schema.CollectionName).WithColumns(pkColumn, vecColumn)) + common.CheckErr(t, err1, true) + require.EqualValues(t, nb, upsertRes.UpsertCount) + + // 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}). + WithFilter(fmt.Sprintf("%d <= %s", upsertPks[0], common.DefaultInt64FieldName))) + common.CheckErr(t, err, true) + common.EqualColumn(t, vecColumn, resSet.GetColumn(common.DefaultFloatVecFieldName)) + + // upsert without pks -> error + vecColumn = hp.GenColumnData(nb, entity.FieldTypeFloatVector, *hp.TNewDataOption()) + _, err = mc.Upsert(ctx, client.NewColumnBasedInsertOption(schema.CollectionName).WithColumns(vecColumn)) + common.CheckErr(t, err, false, "has no corresponding fieldData pass in: invalid parameter") } // test upsert with invalid collection / partition name @@ -379,7 +411,7 @@ func TestUpsertDynamicField(t *testing.T) { // create -> insert [0, 3000) -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -422,7 +454,7 @@ func TestUpsertWithoutLoading(t *testing.T) { // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption()) - prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema, common.DefaultNb), hp.TNewDataOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) // upsert upsertNb := 10