mirror of https://github.com/milvus-io/milvus.git
[skip ci]Fix golint warnings in typeutil (#9302)
Signed-off-by: Xiangyu Wang <xiangyu.wang@zilliz.com>pull/9318/head
parent
e7aa5eebd6
commit
4722f5991b
|
@ -34,7 +34,7 @@ func BytesToFloat32(bytes []byte) float32 {
|
|||
return math.Float32frombits(bits)
|
||||
}
|
||||
|
||||
// BytesToUint64 converts a byte slice to uint64.
|
||||
// BytesToInt64 converts a byte slice to uint64.
|
||||
func BytesToInt64(b []byte) (int64, error) {
|
||||
if len(b) != 8 {
|
||||
return 0, fmt.Errorf("invalid data, must 8 bytes, but %d", len(b))
|
||||
|
@ -43,7 +43,7 @@ func BytesToInt64(b []byte) (int64, error) {
|
|||
return int64(binary.BigEndian.Uint64(b)), nil
|
||||
}
|
||||
|
||||
// Uint64ToBytes converts uint64 to a byte slice.
|
||||
// Int64ToBytes converts uint64 to a byte slice.
|
||||
func Int64ToBytes(v int64) []byte {
|
||||
b := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(b, uint64(v))
|
||||
|
@ -66,6 +66,7 @@ func Uint64ToBytes(v uint64) []byte {
|
|||
return b
|
||||
}
|
||||
|
||||
// SliceRemoveDuplicate is used to dedup a Slice
|
||||
func SliceRemoveDuplicate(a interface{}) (ret []interface{}) {
|
||||
if reflect.TypeOf(a).Kind() != reflect.Slice {
|
||||
fmt.Printf("input is not slice but %T\n", a)
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/spaolacci/murmur3"
|
||||
)
|
||||
|
||||
// Hash32Bytes hashing a byte array to uint32
|
||||
func Hash32Bytes(b []byte) (uint32, error) {
|
||||
h := murmur3.New32()
|
||||
if _, err := h.Write(b); err != nil {
|
||||
|
@ -26,6 +27,7 @@ func Hash32Bytes(b []byte) (uint32, error) {
|
|||
return h.Sum32() & 0x7fffffff, nil
|
||||
}
|
||||
|
||||
// Hash32Uint64 hashing an uint64 nubmer to uint32
|
||||
func Hash32Uint64(v uint64) (uint32, error) {
|
||||
// need unsafe package to get element byte size
|
||||
/* #nosec G103 */
|
||||
|
@ -34,10 +36,12 @@ func Hash32Uint64(v uint64) (uint32, error) {
|
|||
return Hash32Bytes(b)
|
||||
}
|
||||
|
||||
// Hash32Int64 hashing an int64 number to uint32
|
||||
func Hash32Int64(v int64) (uint32, error) {
|
||||
return Hash32Uint64(uint64(v))
|
||||
}
|
||||
|
||||
// Hash32String hashing a string to int64
|
||||
func Hash32String(s string) (int64, error) {
|
||||
b := []byte(s)
|
||||
v, err := Hash32Bytes(b)
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
||||
)
|
||||
|
||||
// EstimateSizePerRecord returns the estimate size of a record in a collection
|
||||
func EstimateSizePerRecord(schema *schemapb.CollectionSchema) (int, error) {
|
||||
res := 0
|
||||
for _, fs := range schema.Fields {
|
||||
|
@ -60,6 +61,7 @@ func EstimateSizePerRecord(schema *schemapb.CollectionSchema) (int, error) {
|
|||
return res, nil
|
||||
}
|
||||
|
||||
// SchemaHelper provides methods to get the schema of fields
|
||||
type SchemaHelper struct {
|
||||
schema *schemapb.CollectionSchema
|
||||
nameOffset map[string]int
|
||||
|
@ -67,6 +69,7 @@ type SchemaHelper struct {
|
|||
primaryKeyOffset int
|
||||
}
|
||||
|
||||
// CreateSchemaHelper returns a new SchemaHelper object
|
||||
func CreateSchemaHelper(schema *schemapb.CollectionSchema) (*SchemaHelper, error) {
|
||||
if schema == nil {
|
||||
return nil, errors.New("schema is nil")
|
||||
|
@ -91,6 +94,7 @@ func CreateSchemaHelper(schema *schemapb.CollectionSchema) (*SchemaHelper, error
|
|||
return &schemaHelper, nil
|
||||
}
|
||||
|
||||
// GetPrimaryKeyField returns the schema of the primary key
|
||||
func (helper *SchemaHelper) GetPrimaryKeyField() (*schemapb.FieldSchema, error) {
|
||||
if helper.primaryKeyOffset == -1 {
|
||||
return nil, fmt.Errorf("no primary in schema")
|
||||
|
@ -98,6 +102,7 @@ func (helper *SchemaHelper) GetPrimaryKeyField() (*schemapb.FieldSchema, error)
|
|||
return helper.schema.Fields[helper.primaryKeyOffset], nil
|
||||
}
|
||||
|
||||
// GetFieldFromName is used to find the schema by field name
|
||||
func (helper *SchemaHelper) GetFieldFromName(fieldName string) (*schemapb.FieldSchema, error) {
|
||||
offset, ok := helper.nameOffset[fieldName]
|
||||
if !ok {
|
||||
|
@ -106,6 +111,7 @@ func (helper *SchemaHelper) GetFieldFromName(fieldName string) (*schemapb.FieldS
|
|||
return helper.schema.Fields[offset], nil
|
||||
}
|
||||
|
||||
// GetFieldFromID returns the schema of specified field
|
||||
func (helper *SchemaHelper) GetFieldFromID(fieldID int64) (*schemapb.FieldSchema, error) {
|
||||
offset, ok := helper.idOffset[fieldID]
|
||||
if !ok {
|
||||
|
@ -114,6 +120,7 @@ func (helper *SchemaHelper) GetFieldFromID(fieldID int64) (*schemapb.FieldSchema
|
|||
return helper.schema.Fields[offset], nil
|
||||
}
|
||||
|
||||
// GetVectorDimFromID returns the dimension of specified field
|
||||
func (helper *SchemaHelper) GetVectorDimFromID(filedID int64) (int, error) {
|
||||
sch, err := helper.GetFieldFromID(filedID)
|
||||
if err != nil {
|
||||
|
@ -134,6 +141,7 @@ func (helper *SchemaHelper) GetVectorDimFromID(filedID int64) (int, error) {
|
|||
return 0, fmt.Errorf("fieldID(%d) not has dim", filedID)
|
||||
}
|
||||
|
||||
// IsVectorType returns true if input is a vector type, otherwise false
|
||||
func IsVectorType(dataType schemapb.DataType) bool {
|
||||
switch dataType {
|
||||
case schemapb.DataType_FloatVector, schemapb.DataType_BinaryVector:
|
||||
|
@ -143,6 +151,7 @@ func IsVectorType(dataType schemapb.DataType) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// IsIntegerType returns true if input is a integer type, otherwise false
|
||||
func IsIntegerType(dataType schemapb.DataType) bool {
|
||||
switch dataType {
|
||||
case schemapb.DataType_Int8, schemapb.DataType_Int16,
|
||||
|
@ -153,6 +162,7 @@ func IsIntegerType(dataType schemapb.DataType) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// IsFloatingType returns true if input is a floating type, otherwise false
|
||||
func IsFloatingType(dataType schemapb.DataType) bool {
|
||||
switch dataType {
|
||||
case schemapb.DataType_Float, schemapb.DataType_Double:
|
||||
|
@ -162,6 +172,7 @@ func IsFloatingType(dataType schemapb.DataType) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// IsBoolType returns true if input is a bool type, otherwise false
|
||||
func IsBoolType(dataType schemapb.DataType) bool {
|
||||
switch dataType {
|
||||
case schemapb.DataType_Bool:
|
||||
|
|
|
@ -11,17 +11,30 @@
|
|||
|
||||
package typeutil
|
||||
|
||||
// Timestamp is an alias of uint64
|
||||
type Timestamp = uint64
|
||||
|
||||
// IntPrimaryKey is an alias of int64
|
||||
type IntPrimaryKey = int64
|
||||
|
||||
// UniqueID is an alias of int64
|
||||
type UniqueID = int64
|
||||
|
||||
const (
|
||||
RootCoordRole = "RootCoord"
|
||||
ProxyRole = "Proxy"
|
||||
// RootCoordRole is a constant represent RootCoord
|
||||
RootCoordRole = "RootCoord"
|
||||
// ProxyRole is a constant represent Proxy
|
||||
ProxyRole = "Proxy"
|
||||
// QueryCoordRole is a constant represent QueryCoord
|
||||
QueryCoordRole = "QueryCoord"
|
||||
QueryNodeRole = "QueryNode"
|
||||
// QueryNodeRole is a constant represent QueryNode
|
||||
QueryNodeRole = "QueryNode"
|
||||
// IndexCoordRole is a constant represent IndexCoord
|
||||
IndexCoordRole = "IndexCoord"
|
||||
IndexNodeRole = "IndexNode"
|
||||
DataCoordRole = "DataCoord"
|
||||
DataNodeRole = "DataNode"
|
||||
// IndexNodeRole is a constant represent IndexNode
|
||||
IndexNodeRole = "IndexNode"
|
||||
// DataCoordRole is a constant represent DataCoord
|
||||
DataCoordRole = "DataCoord"
|
||||
// DataNodeRole is a constant represent DataNode
|
||||
DataNodeRole = "DataNode"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue