Repository: milvus-io/milvus-sdk-go
Pull request #467 (2023-05-25 07:44:39)

Add Logical partition num options for create collection
See also milvus-io/milvus#24402
/kind improvement

sre-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/467#" title="Author self-approved">congqixia</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/master/OWNERS)~~ [congqixia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/467?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) Report
> Merging [#467](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/467?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (772357c) into [master](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/commit/096d10508ff8dea5eb2ab8649ef3ecc2596030db?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) (096d105) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head 772357c differs from pull request most recent head b06cfbe. Consider uploading reports for the commit b06cfbe to get more accurate results

[![Impacted file tree graph](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/467/graphs/tree.svg?width=650&height=150&src=pr&token=WJK43PV390&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/467?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io)

```diff
@@            Coverage Diff             @@
##           master     #467      +/-   ##
==========================================
+ Coverage   84.77%   84.78%   +0.01%     
==========================================
  Files          35       35              
  Lines        3283     3286       +3     
==========================================
+ Hits         2783     2786       +3     
  Misses        397      397              
  Partials      103      103              
```


| [Impacted Files](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/467?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io) | Coverage Δ | |
|---|---|---|
| [client/collection.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/467?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-Y2xpZW50L2NvbGxlY3Rpb24uZ28=) | `87.81% <100.00%> (+0.04%)` | :arrow_up: |
| [client/options.go](https://app.codecov.io/gh/milvus-io/milvus-sdk-go/pull/467?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=milvus-io#diff-Y2xpZW50L29wdGlvbnMuZ28=) | `68.00% <100.00%> (+1.33%)` | :arrow_up: |


Patch:
diff --git a/client/collection.go b/client/collection.go
index 1cd9e4c..0992457 100644
--- a/client/collection.go
+++ b/client/collection.go
@@ -104,6 +104,7 @@ func (c *GrpcClient) CreateCollection(ctx context.Context, collSchema *entity.Sc
 		// default consistency level is strong
 		// to be consistent with previous version
 		ConsistencyLevel: common.ConsistencyLevel_Bounded,
+		NumPartitions:    0,
 	}
 	// apply options on request
 	for _, opt := range opts {
diff --git a/client/options.go b/client/options.go
index b1fa0b5..f992490 100644
--- a/client/options.go
+++ b/client/options.go
@@ -37,6 +37,13 @@ func WithCollectionProperty(key string, value string) CreateCollectionOption {
 	}
 }
 
+// WithPartitionNum returns a create collection options to set physical partition number when logical partition feature.
+func WithPartitionNum(partitionNums int64) CreateCollectionOption {
+	return func(req *server.CreateCollectionRequest) {
+		req.NumPartitions = partitionNums
+	}
+}
+
 // LoadCollectionOption is an option that is used to modify LoadCollectionRequest
 type LoadCollectionOption func(*server.LoadCollectionRequest)
 


Test patch:
diff --git a/client/options_test.go b/client/options_test.go
index b876238..e7f8ea0 100644
--- a/client/options_test.go
+++ b/client/options_test.go
@@ -12,6 +12,7 @@
 package client
 
 import (
+	"math/rand"
 	"testing"
 
 	common "github.com/milvus-io/milvus-proto/go-api/commonpb"
@@ -44,6 +45,19 @@ func TestLoadCollectionWithReplicaNumber(t *testing.T) {
 	assert.Equal(t, testMultiReplicaNumber, req.GetReplicaNumber())
 }
 
+func TestCreateCollectionWithPartitionNum(t *testing.T) {
+	partitionNum := rand.Int63n(1000) + 1
+	opt := WithPartitionNum(partitionNum)
+	assert.NotNil(t, opt)
+	req := &server.CreateCollectionRequest{}
+
+	assert.NotPanics(t, func() {
+		opt(req)
+	})
+
+	assert.Equal(t, partitionNum, req.GetNumPartitions())
+}
+
 func TestMakeSearchQueryOption(t *testing.T) {
 	c := &entity.Collection{
 		Name:             "999",