milvus/internal/masterservice/util.go
neza2017 262c484cec
the return struct of "DescribeIndex" should contain "filed_name" (#5055)
Signed-off-by: yefu.chen <yefu.chen@zilliz.com>
2021-04-27 02:30:55 +00:00

69 lines
1.9 KiB
Go

// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
package masterservice
import (
"fmt"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/etcdpb"
"github.com/milvus-io/milvus/internal/proto/schemapb"
"github.com/milvus-io/milvus/internal/util/typeutil"
)
//return
func EqualKeyPairArray(p1 []*commonpb.KeyValuePair, p2 []*commonpb.KeyValuePair) bool {
if len(p1) != len(p2) {
return false
}
m1 := make(map[string]string)
for _, p := range p1 {
m1[p.Key] = p.Value
}
for _, p := range p2 {
val, ok := m1[p.Key]
if !ok {
return false
}
if val != p.Value {
return false
}
}
return true
}
func GetFieldSchemaByID(coll *etcdpb.CollectionInfo, fieldID typeutil.UniqueID) (*schemapb.FieldSchema, error) {
for _, f := range coll.Schema.Fields {
if f.FieldID == fieldID {
return f, nil
}
}
return nil, fmt.Errorf("field id = %d not found", fieldID)
}
//GetFieldSchemaByIndexID return the field schema by it's index id
func GetFieldSchemaByIndexID(coll *etcdpb.CollectionInfo, idxID typeutil.UniqueID) (*schemapb.FieldSchema, error) {
var fieldID typeutil.UniqueID
exist := false
for _, f := range coll.FieldIndexes {
if f.IndexID == idxID {
fieldID = f.FiledID
exist = true
break
}
}
if !exist {
return nil, fmt.Errorf("index id = %d is not attach to any field", idxID)
}
return GetFieldSchemaByID(coll, fieldID)
}