Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Logical partition num options for create collection #467

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions client/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package client

import (
"math/rand"
"testing"

common "github.com/milvus-io/milvus-proto/go-api/commonpb"
Expand Down Expand Up @@ -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",
Expand Down