Skip to content

Commit

Permalink
enhance: Support InMemory option for ListCollection (#768)
Browse files Browse the repository at this point in the history
Support specifiy check in-memory status when use `ListCollections`

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Jun 11, 2024
1 parent dd7078c commit 302e564
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Client interface {
// NewCollection intializeds a new collection with pre defined attributes
NewCollection(ctx context.Context, collName string, dimension int64, opts ...CreateCollectionOption) error
// ListCollections list collections from connection
ListCollections(ctx context.Context) ([]*entity.Collection, error)
ListCollections(ctx context.Context, opts ...ListCollectionOption) ([]*entity.Collection, error)
// CreateCollection create collection using provided schema
CreateCollection(ctx context.Context, schema *entity.Schema, shardsNum int32, opts ...CreateCollectionOption) error
// DescribeCollection describe collection meta
Expand Down
13 changes: 12 additions & 1 deletion client/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,25 @@ func handleRespStatus(status *commonpb.Status) error {

// ListCollections list collections from connection
// Note that schema info are not provided in collection list
func (c *GrpcClient) ListCollections(ctx context.Context) ([]*entity.Collection, error) {
func (c *GrpcClient) ListCollections(ctx context.Context, opts ...ListCollectionOption) ([]*entity.Collection, error) {
if c.Service == nil {
return []*entity.Collection{}, ErrClientNotReady
}

o := &listCollectionOpt{}
for _, opt := range opts {
opt(o)
}

req := &milvuspb.ShowCollectionsRequest{
DbName: "",
TimeStamp: 0, // means now
}

if o.showInMemory {
req.Type = milvuspb.ShowType_InMemory
}

resp, err := c.Service.ShowCollections(ctx, req)
if err != nil {
return []*entity.Collection{}, err
Expand Down
12 changes: 12 additions & 0 deletions client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,18 @@ func GetWithOutputFields(outputFields ...string) GetOption {
}
}

type listCollectionOpt struct {
showInMemory bool
}

type ListCollectionOption func(*listCollectionOpt)

func WithShowInMemory(value bool) ListCollectionOption {
return func(opt *listCollectionOpt) {
opt.showInMemory = value
}
}

type DropCollectionOption func(*milvuspb.DropCollectionRequest)

type ReleaseCollectionOption func(*milvuspb.ReleaseCollectionRequest)
Expand Down

0 comments on commit 302e564

Please sign in to comment.