mirror of https://github.com/milvus-io/milvus.git
Parse to map when the key of index params is named params
Signed-off-by: dragondriver <jiquan.long@zilliz.com>pull/4973/head^2
parent
12b2eaf196
commit
da94fbed0a
|
@ -158,6 +158,7 @@ IndexWrapper::BuildWithoutIds(const knowhere::DatasetPtr& dataset) {
|
|||
auto index_mode = get_index_mode();
|
||||
config_[knowhere::meta::ROWS] = dataset->Get<int64_t>(knowhere::meta::ROWS);
|
||||
auto conf_adapter = knowhere::AdapterMgr::GetInstance().GetAdapter(index_type);
|
||||
std::cout << "config_ when build index: " << config_ << std::endl;
|
||||
AssertInfo(conf_adapter->CheckTrain(config_, index_mode), "something wrong in index parameters!");
|
||||
|
||||
if (is_in_need_id_list(index_type)) {
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/zilliztech/milvus-distributed/internal/util/funcutil"
|
||||
|
||||
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
||||
"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
|
||||
|
||||
|
@ -15,6 +17,10 @@ import (
|
|||
"github.com/zilliztech/milvus-distributed/internal/storage"
|
||||
)
|
||||
|
||||
const (
|
||||
paramsKeyToParse = "params"
|
||||
)
|
||||
|
||||
type task interface {
|
||||
ID() UniqueID // return ReqID
|
||||
SetID(uid UniqueID) // set ReqID
|
||||
|
@ -140,6 +146,10 @@ func (it *IndexBuildTask) Rollback() error {
|
|||
func (it *IndexBuildTask) Execute() error {
|
||||
log.Println("start build index ...")
|
||||
var err error
|
||||
|
||||
log.Println("type params: ", it.cmd.Req.GetTypeParams())
|
||||
log.Println("index params: ", it.cmd.Req.GetIndexParams())
|
||||
|
||||
typeParams := make(map[string]string)
|
||||
for _, kvPair := range it.cmd.Req.GetTypeParams() {
|
||||
key, value := kvPair.GetKey(), kvPair.GetValue()
|
||||
|
@ -147,7 +157,17 @@ func (it *IndexBuildTask) Execute() error {
|
|||
if ok {
|
||||
return errors.New("duplicated key in type params")
|
||||
}
|
||||
typeParams[key] = value
|
||||
if key == paramsKeyToParse {
|
||||
params, err := funcutil.ParseIndexParamsMap(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for pk, pv := range params {
|
||||
typeParams[pk] = pv
|
||||
}
|
||||
} else {
|
||||
typeParams[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
indexParams := make(map[string]string)
|
||||
|
@ -157,7 +177,17 @@ func (it *IndexBuildTask) Execute() error {
|
|||
if ok {
|
||||
return errors.New("duplicated key in index params")
|
||||
}
|
||||
indexParams[key] = value
|
||||
if key == paramsKeyToParse {
|
||||
params, err := funcutil.ParseIndexParamsMap(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for pk, pv := range params {
|
||||
indexParams[pk] = pv
|
||||
}
|
||||
} else {
|
||||
indexParams[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
it.index, err = NewCIndex(typeParams, indexParams)
|
||||
|
|
|
@ -2,6 +2,7 @@ package funcutil
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
|
@ -60,3 +61,17 @@ func WaitForComponentReady(service StateComponent, serviceName string, attempts
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseIndexParamsMap(mStr string) (map[string]string, error) {
|
||||
buffer := make(map[string]interface{})
|
||||
err := json.Unmarshal([]byte(mStr), &buffer)
|
||||
if err != nil {
|
||||
return nil, errors.New("Unmarshal params failed")
|
||||
}
|
||||
ret := make(map[string]string)
|
||||
for key, value := range buffer {
|
||||
valueStr := fmt.Sprintf("%v", value)
|
||||
ret[key] = valueStr
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue