Skip to content

Commit

Permalink
Compatible with scalar index types marisa-trie and Ascending (#27638)
Browse files Browse the repository at this point in the history
Signed-off-by: xige-16 <[email protected]>
  • Loading branch information
xige-16 authored Oct 15, 2023
1 parent c5ea313 commit 6cbb678
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 7 deletions.
16 changes: 11 additions & 5 deletions internal/proxy/task_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,21 @@ func (cit *createIndexTask) parseIndexParams() error {
if !isVecIndex {
specifyIndexType, exist := indexParamsMap[common.IndexTypeKey]
if cit.fieldSchema.DataType == schemapb.DataType_VarChar {
if exist && specifyIndexType != DefaultStringIndexType {
if !exist {
indexParamsMap[common.IndexTypeKey] = DefaultStringIndexType
}

if exist && !validateStringIndexType(specifyIndexType) {
return merr.WrapErrParameterInvalid(DefaultStringIndexType, specifyIndexType, "index type not match")
}
indexParamsMap[common.IndexTypeKey] = DefaultStringIndexType
} else if typeutil.IsArithmetic(cit.fieldSchema.DataType) {
if exist && specifyIndexType != DefaultIndexType {
return merr.WrapErrParameterInvalid(DefaultIndexType, specifyIndexType, "index type not match")
if !exist {
indexParamsMap[common.IndexTypeKey] = DefaultArithmeticIndexType
}

if exist && !validateArithmeticIndexType(specifyIndexType) {
return merr.WrapErrParameterInvalid(DefaultArithmeticIndexType, specifyIndexType, "index type not match")
}
indexParamsMap[common.IndexTypeKey] = DefaultIndexType
} else {
return merr.WrapErrParameterInvalid("supported field",
fmt.Sprintf("create index on %s field", cit.fieldSchema.DataType.String()),
Expand Down
112 changes: 112 additions & 0 deletions internal/proxy/task_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,118 @@ func Test_parseIndexParams(t *testing.T) {
assert.Error(t, err)
})

t.Run("create index on VarChar field", func(t *testing.T) {
cit := &createIndexTask{
req: &milvuspb.CreateIndexRequest{
ExtraParams: []*commonpb.KeyValuePair{
{
Key: common.IndexTypeKey,
Value: DefaultStringIndexType,
},
},
IndexName: "",
},
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
Name: "FieldID",
IsPrimaryKey: false,
DataType: schemapb.DataType_VarChar,
},
}
err := cit.parseIndexParams()
assert.NoError(t, err)
})

t.Run("create index on Arithmetic field", func(t *testing.T) {
cit := &createIndexTask{
req: &milvuspb.CreateIndexRequest{
ExtraParams: []*commonpb.KeyValuePair{
{
Key: common.IndexTypeKey,
Value: DefaultArithmeticIndexType,
},
},
IndexName: "",
},
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
Name: "FieldID",
IsPrimaryKey: false,
DataType: schemapb.DataType_Int64,
},
}
err := cit.parseIndexParams()
assert.NoError(t, err)
})

// Compatible with the old version <= 2.3.0
t.Run("create marisa-trie index on VarChar field", func(t *testing.T) {
cit := &createIndexTask{
req: &milvuspb.CreateIndexRequest{
ExtraParams: []*commonpb.KeyValuePair{
{
Key: common.IndexTypeKey,
Value: "marisa-trie",
},
},
IndexName: "",
},
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
Name: "FieldID",
IsPrimaryKey: false,
DataType: schemapb.DataType_VarChar,
},
}
err := cit.parseIndexParams()
assert.NoError(t, err)
})

// Compatible with the old version <= 2.3.0
t.Run("create Asceneding index on Arithmetic field", func(t *testing.T) {
cit := &createIndexTask{
req: &milvuspb.CreateIndexRequest{
ExtraParams: []*commonpb.KeyValuePair{
{
Key: common.IndexTypeKey,
Value: "Asceneding",
},
},
IndexName: "",
},
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
Name: "FieldID",
IsPrimaryKey: false,
DataType: schemapb.DataType_Int64,
},
}
err := cit.parseIndexParams()
assert.NoError(t, err)
})

t.Run("create unsupported index on Arithmetic field", func(t *testing.T) {
cit := &createIndexTask{
req: &milvuspb.CreateIndexRequest{
ExtraParams: []*commonpb.KeyValuePair{
{
Key: common.IndexTypeKey,
Value: "invalid_type",
},
},
IndexName: "",
},
fieldSchema: &schemapb.FieldSchema{
FieldID: 101,
Name: "FieldID",
IsPrimaryKey: false,
DataType: schemapb.DataType_Int64,
},
}
err := cit.parseIndexParams()
assert.Error(t, err)
})

t.Run("create index on array field", func(t *testing.T) {
cit3 := &createIndexTask{
Condition: nil,
Expand Down
14 changes: 12 additions & 2 deletions internal/proxy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const (

defaultMaxArrayCapacity = 4096

// DefaultIndexType name of default index type for scalar field
DefaultIndexType = "STL_SORT"
// DefaultArithmeticIndexType name of default index type for scalar field
DefaultArithmeticIndexType = "STL_SORT"

// DefaultStringIndexType name of default index type for varChar/string field
DefaultStringIndexType = "Trie"
Expand Down Expand Up @@ -244,6 +244,16 @@ func validatePartitionTag(partitionTag string, strictCheck bool) error {
return nil
}

func validateStringIndexType(indexType string) bool {
// compatible with the index type marisa-trie of attu versions prior to 2.3.0
return indexType == DefaultStringIndexType || indexType == "marisa-trie"
}

func validateArithmeticIndexType(indexType string) bool {
// compatible with the index type Asceneding of attu versions prior to 2.3.0
return indexType == DefaultArithmeticIndexType || indexType == "Asceneding"
}

func validateFieldName(fieldName string) error {
fieldName = strings.TrimSpace(fieldName)

Expand Down

0 comments on commit 6cbb678

Please sign in to comment.