mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 04:49:08 +08:00
d7f38a803d
Signed-off-by: SimFG <bang.fu@zilliz.com> Signed-off-by: SimFG <bang.fu@zilliz.com>
104 lines
2.1 KiB
Go
104 lines
2.1 KiB
Go
package indexcgowrapper
|
|
|
|
import (
|
|
"github.com/milvus-io/milvus/api/schemapb"
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
)
|
|
|
|
const (
|
|
keyRawArr = "key_raw_arr"
|
|
)
|
|
|
|
type Dataset struct {
|
|
DType schemapb.DataType
|
|
Data map[string]interface{}
|
|
}
|
|
|
|
func GenFloatVecDataset(vectors []float32) *Dataset {
|
|
return &Dataset{
|
|
DType: schemapb.DataType_FloatVector,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: vectors,
|
|
},
|
|
}
|
|
}
|
|
|
|
func GenBinaryVecDataset(vectors []byte) *Dataset {
|
|
return &Dataset{
|
|
DType: schemapb.DataType_BinaryVector,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: vectors,
|
|
},
|
|
}
|
|
}
|
|
|
|
func GenDataset(data storage.FieldData) *Dataset {
|
|
switch f := data.(type) {
|
|
case *storage.BoolFieldData:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_Bool,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: f.Data,
|
|
},
|
|
}
|
|
case *storage.Int8FieldData:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_Int8,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: f.Data,
|
|
},
|
|
}
|
|
case *storage.Int16FieldData:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_Int16,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: f.Data,
|
|
},
|
|
}
|
|
case *storage.Int32FieldData:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_Int32,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: f.Data,
|
|
},
|
|
}
|
|
case *storage.Int64FieldData:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_Int64,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: f.Data,
|
|
},
|
|
}
|
|
case *storage.FloatFieldData:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_Float,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: f.Data,
|
|
},
|
|
}
|
|
case *storage.DoubleFieldData:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_Double,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: f.Data,
|
|
},
|
|
}
|
|
case *storage.StringFieldData:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_String,
|
|
Data: map[string]interface{}{
|
|
keyRawArr: f.Data,
|
|
},
|
|
}
|
|
case *storage.BinaryVectorFieldData:
|
|
return GenBinaryVecDataset(f.Data)
|
|
case *storage.FloatVectorFieldData:
|
|
return GenFloatVecDataset(f.Data)
|
|
default:
|
|
return &Dataset{
|
|
DType: schemapb.DataType_None,
|
|
Data: nil,
|
|
}
|
|
}
|
|
}
|