2022-03-21 14:23:24 +08:00
|
|
|
package indexcgowrapper
|
|
|
|
|
|
|
|
import (
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2022-03-21 14:23:24 +08:00
|
|
|
"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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|