Skip to content

Commit

Permalink
Export indexed rows for descrieb_index
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Zhang <[email protected]>
  • Loading branch information
xiaocai2333 committed Jul 11, 2024
1 parent a8b2932 commit d183214
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 4 deletions.
6 changes: 6 additions & 0 deletions client/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,16 @@ func (c *GrpcClient) DescribeIndex(ctx context.Context, collName string, fieldNa
}
params := entity.KvPairsMap(info.Params)
it := params["index_type"] // TODO change to const
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
8 changes: 8 additions & 0 deletions client/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func TestGrpcClientDescribeIndex(t *testing.T) {
"nlist": "1024",
"metric_type": "IP",
}),
TotalRows: 10000,
IndexedRows: 4000,
PendingIndexRows: 10000,
State: commonpb.IndexState_InProgress,
},
}
s, err := SuccessStatus()
Expand All @@ -127,6 +131,10 @@ func TestGrpcClientDescribeIndex(t *testing.T) {
idxes, err := c.DescribeIndex(ctx, testCollectionName, fieldName)
assert.Nil(t, err)
assert.NotNil(t, idxes)
assert.Equal(t, idxes[0].Progress()["total_rows"], "10000")
assert.Equal(t, idxes[0].Progress()["indexed_rows"], "4000")
assert.Equal(t, idxes[0].Progress()["pending_index_rows"], "10000")
assert.Equal(t, idxes[0].Progress()["state"], "InProgress")
})

t.Run("Service return errors", func(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions entity/genidx/genidx.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func(i *Index{{.IdxName}}) Params() map[string]string {
}
}
// Progress returns index progress information, only fill it after DescribeIndex for GenericIndex
func(i *Index{{.IdxName}}) Progress() map[string]string {
return map[string]string {}
}
// NewIndex{{.IdxName}} create index with construction parameters
func NewIndex{{.IdxName}}(metricType MetricType, {{range .ConstructParams}}{{with .}}
{{.Name}} {{.ParamType}},
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 @@ -81,6 +83,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 @@ -136,7 +139,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 @@ -151,13 +163,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) Index {
index := GenericIndex{
baseIndex: baseIndex{
it: it,
name: name,
},
params: params,
}
for _, opt := range opts {
opt(&index)
}
return index
}
8 changes: 8 additions & 0 deletions entity/index_cagra.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (i *IndexGPUCagra) Params() map[string]string {
}
}

func (i *IndexGPUCagra) Progress() map[string]string {
return map[string]string{}
}

type IndexGPUCagraSearchParam struct {
baseSearchParams
}
Expand Down Expand Up @@ -131,6 +135,10 @@ func (i *IndexGPUBruteForce) Params() map[string]string {
}
}

func (i *IndexGPUBruteForce) Progress() map[string]string {
return map[string]string{}
}

type IndexGPUBruteForceSearchParam struct {
baseSearchParams
}
Expand Down
4 changes: 4 additions & 0 deletions entity/index_scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func (i *indexScalar) Params() map[string]string {
return result
}

func (i *indexScalar) Progress() map[string]string {
return map[string]string{}
}

func NewScalarIndex() Index {
return &indexScalar{
baseIndex: baseIndex{},
Expand Down
8 changes: 8 additions & 0 deletions entity/index_sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (i *IndexSparseInverted) Params() map[string]string {
}
}

func (i *IndexSparseInverted) Progress() map[string]string {
return map[string]string{}
}

type IndexSparseInvertedSearchParam struct {
baseSearchParams
}
Expand Down Expand Up @@ -87,6 +91,10 @@ func (i *IndexSparseWAND) Params() map[string]string {
}
}

func (i *IndexSparseWAND) Progress() map[string]string {
return map[string]string{}
}

// IndexSparseWAND index type for SPARSE_WAND, weak-and
func NewIndexSparseWAND(metricType MetricType, dropRatio float64) (*IndexSparseWAND, error) {
if dropRatio < 0 || dropRatio >= 1.0 {
Expand Down
65 changes: 65 additions & 0 deletions entity/indexes_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d183214

Please sign in to comment.