Skip to content

Commit

Permalink
Change LoadCollection interface
Browse files Browse the repository at this point in the history
Signed-off-by: fishpenguin <[email protected]>
  • Loading branch information
fishpenguin committed Dec 22, 2020
1 parent 2db1ba4 commit 2924a27
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 249 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## milvus-sdk-go 0.4.5

### Bug
---

### Improvement
---

### Feature
---
- \#82 - Change LoadCollection interface

### Task
---

## milvus-sdk-go 0.4.2 (2020-06-13)

### Bug
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Go SDK for [Milvus](https://github.com/milvus-io/milvus). To contribute code to

|Milvus version| Recommended Go SDK version |
|:-----:|:-----:|
| 0.10.5 | 0.4.5|
| 0.10.4 | 0.4.4|
| 0.10.3 | 0.4.4|
| 0.10.2 | 0.4.4|
Expand Down
3 changes: 2 additions & 1 deletion examples/MilvusClientExample.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ func example(address string, port string) {
println(indexParam.CollectionName + "----index type:" + strconv.Itoa(int(indexParam.IndexType)))

//Preload collection
status, err = client.LoadCollection(collectionName)
loadCollectionParam := milvus.LoadCollectionParam{collectionName, nil}
status, err = client.LoadCollection(loadCollectionParam)
if err != nil {
println("PreloadCollection rpc failed: " + err.Error())
return
Expand Down
12 changes: 6 additions & 6 deletions milvus/ClientProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (client *Milvusclient) Connect(connectParam ConnectParam) error {
println("Get server version status: " + status.GetMessage())
return err
}
if (serverVersion[0:4] != "0.10") {
if serverVersion[0:4] != "0.10" {
println("Server version check failed, this client supposed to connect milvus-0.10.x")
client.Instance = nil
err = errors.New("Connecto server failed, please check server version.")
Expand Down Expand Up @@ -169,7 +169,7 @@ func (client *Milvusclient) GetEntityByID(collectionName string, vector_id []int
entityLen := len(grpcVectorData.VectorsData)
var entity = make([]Entity, entityLen)
var i int64
for i = 0;i < int64(entityLen); i++ {
for i = 0; i < int64(entityLen); i++ {
entity[i].FloatData = grpcVectorData.VectorsData[i].FloatData
entity[i].BinaryData = grpcVectorData.VectorsData[i].BinaryData
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func (client *Milvusclient) Search(searchParam SearchParam) (TopkQueryResult, St
}
nq := topkQueryResult.GetRowNum()
if nq == 0 {
return TopkQueryResult{nil}, status{int64(topkQueryResult.Status.ErrorCode), topkQueryResult.Status.Reason,}, err
return TopkQueryResult{nil}, status{int64(topkQueryResult.Status.ErrorCode), topkQueryResult.Status.Reason}, err
}
var queryResult []QueryResult
topk := int64(len(topkQueryResult.GetIds())) / nq
Expand Down Expand Up @@ -311,9 +311,9 @@ func (client *Milvusclient) ServerStatus() (string, Status, error) {

////////////////////////////////////////////////////////////////////////////

func (client *Milvusclient) LoadCollection(collectionName string) (Status, error) {
grpcCollectionName := pb.CollectionName{collectionName, struct{}{}, nil, 0}
grpcStatus, err := client.Instance.PreloadCollection(grpcCollectionName)
func (client *Milvusclient) LoadCollection(param LoadCollectionParam) (Status, error) {
grpcParam := pb.PreloadCollectionParam{param.CollectionName, param.PartitionTagList, struct{}{}, nil, 0}
grpcStatus, err := client.Instance.PreloadCollection(grpcParam)
if err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion milvus/MilvusClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ type ListIDInSegmentParam struct {
SegmentName string
}

type LoadCollectionParam struct {
CollectionName string
PartitionTagList []string
}

// MilvusClient SDK main interface
type MilvusClient interface {

Expand Down Expand Up @@ -316,7 +321,7 @@ type MilvusClient interface {
// LoadCollection method
// This method is used to preload collection
// return indicate if this operation is successful.
LoadCollection(collectionName string) (Status, error)
LoadCollection(param LoadCollectionParam) (Status, error)

// GetIndexInfo method
// This method is used to describe index
Expand Down
52 changes: 26 additions & 26 deletions milvus/MilvusGrpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type MilvusGrpcClient interface {

DeleteByID(param pb.DeleteByIDParam) (pb.Status, error)

PreloadCollection(collectionName pb.CollectionName) (pb.Status, error)
PreloadCollection(preloadCollectionParam pb.PreloadCollectionParam) (pb.Status, error)

Flush(param pb.FlushParam) (pb.Status, error)

Expand All @@ -92,7 +92,7 @@ func (grpcClient *milvusGrpcClient) CreateCollection(collectionSchema pb.Collect
defer cancel()
reply, err := grpcClient.serviceInstance.CreateCollection(ctx, &collectionSchema)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *reply, err
}
Expand All @@ -102,7 +102,7 @@ func (grpcClient *milvusGrpcClient) HasCollection(collectionName pb.CollectionNa
defer cancel()
boolReply, err := grpcClient.serviceInstance.HasCollection(ctx, &collectionName)
if err != nil {
return pb.BoolReply{nil, false, struct{}{}, nil, 0,}, err
return pb.BoolReply{nil, false, struct{}{}, nil, 0}, err
}
return *boolReply, err
}
Expand All @@ -112,7 +112,7 @@ func (grpcClient *milvusGrpcClient) DescribeCollection(collectionName pb.Collect
defer cancel()
collectionSchema, err := grpcClient.serviceInstance.DescribeCollection(ctx, &collectionName)
if err != nil {
return pb.CollectionSchema{nil, "", 0, 0, 0, nil, struct{}{}, nil, 0,}, err
return pb.CollectionSchema{nil, "", 0, 0, 0, nil, struct{}{}, nil, 0}, err
}
return *collectionSchema, err
}
Expand All @@ -122,7 +122,7 @@ func (grpcClient *milvusGrpcClient) CountCollection(collectionName pb.Collection
defer cancel()
count, err := grpcClient.serviceInstance.CountCollection(ctx, &collectionName)
if err != nil {
return pb.CollectionRowCount{nil, 0, struct{}{}, nil, 0,}, err
return pb.CollectionRowCount{nil, 0, struct{}{}, nil, 0}, err
}
return *count, err
}
Expand All @@ -133,7 +133,7 @@ func (grpcClient *milvusGrpcClient) ShowCollections() (pb.CollectionNameList, er
defer cancel()
collectionNameList, err := grpcClient.serviceInstance.ShowCollections(ctx, &cmd)
if err != nil {
return pb.CollectionNameList{nil, nil, struct{}{}, nil, 0,}, err
return pb.CollectionNameList{nil, nil, struct{}{}, nil, 0}, err
}
return *collectionNameList, err
}
Expand All @@ -143,7 +143,7 @@ func (grpcClient *milvusGrpcClient) ShowCollectionInfo(collectionName pb.Collect
defer cancel()
collectionInfo, err := grpcClient.serviceInstance.ShowCollectionInfo(ctx, &collectionName)
if err != nil {
return pb.CollectionInfo{nil, "", struct{}{}, nil, 0,}, err
return pb.CollectionInfo{nil, "", struct{}{}, nil, 0}, err
}
return *collectionInfo, err
}
Expand All @@ -153,7 +153,7 @@ func (grpcClient *milvusGrpcClient) DropCollection(collectionName pb.CollectionN
defer cancel()
status, err := grpcClient.serviceInstance.DropCollection(ctx, &collectionName)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -162,7 +162,7 @@ func (grpcClient *milvusGrpcClient) CreateIndex(indexParam pb.IndexParam) (pb.St
ctx := context.Background()
status, err := grpcClient.serviceInstance.CreateIndex(ctx, &indexParam)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -172,7 +172,7 @@ func (grpcClient *milvusGrpcClient) DescribeIndex(collectionName pb.CollectionNa
defer cancel()
indexParam, err := grpcClient.serviceInstance.DescribeIndex(ctx, &collectionName)
if err != nil {
return pb.IndexParam{nil, "", 0, nil, struct{}{}, nil, 0,}, err
return pb.IndexParam{nil, "", 0, nil, struct{}{}, nil, 0}, err
}
return *indexParam, err
}
Expand All @@ -182,7 +182,7 @@ func (grpcClient *milvusGrpcClient) DropIndex(collectionName pb.CollectionName)
defer cancel()
status, err := grpcClient.serviceInstance.DropIndex(ctx, &collectionName)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -192,7 +192,7 @@ func (grpcClient *milvusGrpcClient) CreatePartition(partitionParam pb.PartitionP
defer cancel()
status, err := grpcClient.serviceInstance.CreatePartition(ctx, &partitionParam)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -202,7 +202,7 @@ func (grpcClient *milvusGrpcClient) ShowPartitions(collectionName pb.CollectionN
defer cancel()
status, err := grpcClient.serviceInstance.ShowPartitions(ctx, &collectionName)
if err != nil {
return pb.PartitionList{nil, nil, struct{}{}, nil, 0,}, err
return pb.PartitionList{nil, nil, struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -212,7 +212,7 @@ func (grpcClient *milvusGrpcClient) DropPartition(partitionParam pb.PartitionPar
defer cancel()
status, err := grpcClient.serviceInstance.DropPartition(ctx, &partitionParam)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -221,7 +221,7 @@ func (grpcClient *milvusGrpcClient) Insert(insertParam pb.InsertParam) (pb.Vecto
ctx := context.Background()
vectorIds, err := grpcClient.serviceInstance.Insert(ctx, &insertParam)
if err != nil {
return pb.VectorIds{nil, nil, struct{}{}, nil, 0,}, err
return pb.VectorIds{nil, nil, struct{}{}, nil, 0}, err
}
return *vectorIds, err
}
Expand All @@ -230,7 +230,7 @@ func (grpcClient *milvusGrpcClient) GetVectorsByID(identity pb.VectorsIdentity)
ctx := context.Background()
vectorsData, err := grpcClient.serviceInstance.GetVectorsByID(ctx, &identity)
if err != nil {
return pb.VectorsData{nil, nil, struct{}{}, nil, 0,}, err
return pb.VectorsData{nil, nil, struct{}{}, nil, 0}, err
}
return *vectorsData, err
}
Expand All @@ -239,7 +239,7 @@ func (grpcClient *milvusGrpcClient) GetVectorIDs(param pb.GetVectorIDsParam) (pb
ctx := context.Background()
status, err := grpcClient.serviceInstance.GetVectorIDs(ctx, &param)
if err != nil {
return pb.VectorIds{nil, nil, struct{}{}, nil, 0,}, err
return pb.VectorIds{nil, nil, struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -248,7 +248,7 @@ func (grpcClient *milvusGrpcClient) Search(searchParam pb.SearchParam) (*pb.TopK
ctx := context.Background()
topkQueryResult, err := grpcClient.serviceInstance.Search(ctx, &searchParam)
if err != nil {
return &pb.TopKQueryResult{nil, 0, nil, nil, struct{}{}, nil, 0,}, err
return &pb.TopKQueryResult{nil, 0, nil, nil, struct{}{}, nil, 0}, err
}
return topkQueryResult, err
}
Expand All @@ -257,7 +257,7 @@ func (grpcClient *milvusGrpcClient) SearchInFiles(searchInFilesParam pb.SearchIn
ctx := context.Background()
topkQueryResult, err := grpcClient.serviceInstance.SearchInFiles(ctx, &searchInFilesParam)
if err != nil {
return &pb.TopKQueryResult{nil, 0, nil, nil, struct{}{}, nil, 0,}, err
return &pb.TopKQueryResult{nil, 0, nil, nil, struct{}{}, nil, 0}, err
}
return topkQueryResult, err
}
Expand All @@ -267,7 +267,7 @@ func (grpcClient *milvusGrpcClient) Cmd(command pb.Command) (pb.StringReply, err
defer cancel()
stringReply, err := grpcClient.serviceInstance.Cmd(ctx, &command)
if err != nil {
return pb.StringReply{nil, "", struct{}{}, nil, 0,}, err
return pb.StringReply{nil, "", struct{}{}, nil, 0}, err
}
return *stringReply, err
}
Expand All @@ -277,17 +277,17 @@ func (grpcClient *milvusGrpcClient) DeleteByID(param pb.DeleteByIDParam) (pb.Sta
defer cancel()
status, err := grpcClient.serviceInstance.DeleteByID(ctx, &param)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}

func (grpcClient *milvusGrpcClient) PreloadCollection(collectionName pb.CollectionName) (pb.Status, error) {
func (grpcClient *milvusGrpcClient) PreloadCollection(preloadCollectionParam pb.PreloadCollectionParam) (pb.Status, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
status, err := grpcClient.serviceInstance.PreloadCollection(ctx, &collectionName)
status, err := grpcClient.serviceInstance.PreloadCollection(ctx, &preloadCollectionParam)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -297,7 +297,7 @@ func (grpcClient *milvusGrpcClient) Flush(param pb.FlushParam) (pb.Status, error
defer cancel()
status, err := grpcClient.serviceInstance.Flush(ctx, &param)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}
Expand All @@ -307,7 +307,7 @@ func (grpcClient *milvusGrpcClient) Compact(collectionName pb.CollectionName) (p
defer cancel()
status, err := grpcClient.serviceInstance.Compact(ctx, &collectionName)
if err != nil {
return pb.Status{0, "", struct{}{}, nil, 0,}, err
return pb.Status{0, "", struct{}{}, nil, 0}, err
}
return *status, err
}
Loading

0 comments on commit 2924a27

Please sign in to comment.