diff --git a/client/index.go b/client/index.go index b5c81a347..78a3addb5 100644 --- a/client/index.go +++ b/client/index.go @@ -179,12 +179,12 @@ func (c *GrpcClient) AlterIndex(ctx context.Context, collName string, indexName } // DescribeIndex describe index -func (c *GrpcClient) DescribeIndex(ctx context.Context, collName string, fieldName string, opts ...IndexOption) ([]entity.Index, error) { +func (c *GrpcClient) DescribeIndex(ctx context.Context, collName string, fieldName string, opts ...IndexOption) ([]entity.GenericIndex, error) { if c.Service == nil { - return []entity.Index{}, ErrClientNotReady + return []entity.GenericIndex{}, ErrClientNotReady } if err := c.checkCollField(ctx, collName, fieldName); err != nil { - return []entity.Index{}, err + return []entity.GenericIndex{}, err } idxDesc, err := c.describeIndex(ctx, collName, fieldName, opts...) @@ -192,21 +192,23 @@ func (c *GrpcClient) DescribeIndex(ctx context.Context, collName string, fieldNa return nil, err } - indexes := make([]entity.Index, 0, len(idxDesc)) + indexes := make([]entity.GenericIndex, 0, len(idxDesc)) for _, info := range idxDesc { if fieldName != "" && info.GetFieldName() != fieldName { continue } params := entity.KvPairsMap(info.Params) it := params["index_type"] // TODO change to const - params["total_rows"] = strconv.FormatInt(info.GetTotalRows(), 10) - params["indexed_rows"] = strconv.FormatInt(info.GetIndexedRows(), 10) - params["pending_index_rows"] = strconv.FormatInt(info.GetPendingIndexRows(), 10) - params["state"] = info.GetState().String() + progress := make(map[string]string) + progress["total_rows"] = strconv.FormatInt(info.GetTotalRows(), 10) + progress["indexed_rows"] = strconv.FormatInt(info.GetIndexedRows(), 10) + progress["pending_index_rows"] = strconv.FormatInt(info.GetPendingIndexRows(), 10) + progress["state"] = info.GetState().String() idx := entity.NewGenericIndex( info.IndexName, entity.IndexType(it), params, + entity.WithProgress(progress), ) indexes = append(indexes, idx) } diff --git a/entity/index.go b/entity/index.go index 76adcacca..120891d47 100644 --- a/entity/index.go +++ b/entity/index.go @@ -11,7 +11,9 @@ package entity -import common "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" +import ( + common "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" +) //go:generate go run genidx/genidx.go @@ -80,6 +82,7 @@ type Index interface { Name() string IndexType() IndexType Params() map[string]string + //Progress() map[string]string } // SearchParam interface for index related search param @@ -135,7 +138,16 @@ func (b baseIndex) IndexType() IndexType { // no constraint for index is applied type GenericIndex struct { baseIndex - params map[string]string + params map[string]string + progress map[string]string +} + +type OptionFunc func(GenericIndex) + +func WithProgress(progress map[string]string) OptionFunc { + return func(index GenericIndex) { + index.progress = progress + } } // Params implements Index @@ -150,13 +162,21 @@ func (gi GenericIndex) Params() map[string]string { return m } +func (gi GenericIndex) Progress() map[string]string { + return gi.progress +} + // NewGenericIndex create generic index instance -func NewGenericIndex(name string, it IndexType, params map[string]string) Index { - return GenericIndex{ +func NewGenericIndex(name string, it IndexType, params map[string]string, opts ...OptionFunc) GenericIndex { + index := GenericIndex{ baseIndex: baseIndex{ it: it, name: name, }, params: params, } + for _, opt := range opts { + opt(index) + } + return index }