Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Zhang <[email protected]>
  • Loading branch information
xiaocai2333 committed Jun 25, 2024
1 parent d5750cc commit 9ae19b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
18 changes: 10 additions & 8 deletions client/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,34 +179,36 @@ 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...)
if err != nil {
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)
}
Expand Down
28 changes: 24 additions & 4 deletions entity/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 9ae19b8

Please sign in to comment.