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

Export indexed rows for describe_index #779

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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.

4 changes: 2 additions & 2 deletions test/testcases/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ func TestCreateIndexSparseVector2(t *testing.T) {
// describe index
idx2, err := mc.DescribeIndex(ctx, collName, common.DefaultSparseVecFieldName)
expIndex := entity.NewGenericIndex(common.DefaultSparseVecFieldName, idx.IndexType(), idx.Params())
require.EqualValues(t, expIndex, idx2[0])
require.EqualValues(t, expIndex.Params(), idx2[0].Params())
common.CheckErr(t, err, true)
common.CheckIndexResult(t, idx2, expIndex)
}
Expand Down Expand Up @@ -1448,7 +1448,7 @@ func TestDropIndexCreateIndex(t *testing.T) {

// describe index
ipIndexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName)
require.EqualValues(t, entity.NewGenericIndex(common.DefaultFloatVecFieldName, ipIdx.IndexType(), ipIdx.Params()), ipIndexes[0])
require.EqualValues(t, entity.NewGenericIndex(common.DefaultFloatVecFieldName, ipIdx.IndexType(), ipIdx.Params()).Params(), ipIndexes[0].Params())

// describe collection
t.Log("Issue: https://github.com/milvus-io/milvus-sdk-go/issues/385")
Expand Down
Loading