mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 11:59:00 +08:00
Remove const to enable move semantics and improve schema util functions (#25193)
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
parent
c332c95454
commit
37fe3393d1
@ -291,7 +291,7 @@ VectorDiskAnnIndex<T>::HasRawData() const {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const std::vector<uint8_t>
|
||||
std::vector<uint8_t>
|
||||
VectorDiskAnnIndex<T>::GetVector(const DatasetPtr dataset) const {
|
||||
auto res = index_.GetVectorByIds(*dataset);
|
||||
if (!res.has_value()) {
|
||||
|
@ -73,7 +73,7 @@ class VectorDiskAnnIndex : public VectorIndex {
|
||||
const bool
|
||||
HasRawData() const override;
|
||||
|
||||
const std::vector<uint8_t>
|
||||
std::vector<uint8_t>
|
||||
GetVector(const DatasetPtr dataset) const override;
|
||||
|
||||
void
|
||||
|
@ -59,7 +59,7 @@ class VectorIndex : public IndexBase {
|
||||
virtual const bool
|
||||
HasRawData() const = 0;
|
||||
|
||||
virtual const std::vector<uint8_t>
|
||||
virtual std::vector<uint8_t>
|
||||
GetVector(const DatasetPtr dataset) const = 0;
|
||||
|
||||
IndexType
|
||||
|
@ -244,7 +244,7 @@ VectorMemIndex::HasRawData() const {
|
||||
return index_.HasRawData(GetMetricType());
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>
|
||||
std::vector<uint8_t>
|
||||
VectorMemIndex::GetVector(const DatasetPtr dataset) const {
|
||||
auto res = index_.GetVectorByIds(*dataset);
|
||||
if (!res.has_value()) {
|
||||
|
@ -65,7 +65,7 @@ class VectorMemIndex : public VectorIndex {
|
||||
const bool
|
||||
HasRawData() const override;
|
||||
|
||||
const std::vector<uint8_t>
|
||||
std::vector<uint8_t>
|
||||
GetVector(const DatasetPtr dataset) const override;
|
||||
|
||||
BinarySet
|
||||
|
@ -67,7 +67,7 @@ VectorFieldIndexing::GetDataFromIndex(const int64_t* seg_offsets,
|
||||
ids_ds->SetIds(seg_offsets);
|
||||
ids_ds->SetIsOwner(false);
|
||||
|
||||
auto& vector = index_->GetVector(ids_ds);
|
||||
auto vector = index_->GetVector(ids_ds);
|
||||
|
||||
std::memcpy(output, vector.data(), count * element_size);
|
||||
}
|
||||
|
@ -605,7 +605,7 @@ SegmentSealedImpl::get_vector(FieldId field_id,
|
||||
|
||||
if (has_raw_data) {
|
||||
auto ids_ds = GenIdsDataset(count, ids);
|
||||
auto& vector = vec_index->GetVector(ids_ds);
|
||||
auto vector = vec_index->GetVector(ids_ds);
|
||||
return segcore::CreateVectorDataArrayFrom(
|
||||
vector.data(), count, filed_meta);
|
||||
}
|
||||
|
@ -596,7 +596,7 @@ func (t *searchTask) Requery() error {
|
||||
return err
|
||||
}
|
||||
offsets := make(map[any]int)
|
||||
for i := 0; i < typeutil.GetDataSize(pkFieldData); i++ {
|
||||
for i := 0; i < typeutil.GetPKSize(pkFieldData); i++ {
|
||||
pk := typeutil.GetData(pkFieldData, i)
|
||||
offsets[pk] = i
|
||||
}
|
||||
|
@ -817,26 +817,12 @@ func GetSizeOfIDs(data *schemapb.IDs) int {
|
||||
return result
|
||||
}
|
||||
|
||||
func GetDataSize(fieldData *schemapb.FieldData) int {
|
||||
func GetPKSize(fieldData *schemapb.FieldData) int {
|
||||
switch fieldData.GetType() {
|
||||
case schemapb.DataType_Bool:
|
||||
return len(fieldData.GetScalars().GetBoolData().GetData())
|
||||
case schemapb.DataType_Int8, schemapb.DataType_Int16, schemapb.DataType_Int32:
|
||||
return len(fieldData.GetScalars().GetIntData().GetData())
|
||||
case schemapb.DataType_Int64:
|
||||
return len(fieldData.GetScalars().GetLongData().GetData())
|
||||
case schemapb.DataType_Float:
|
||||
return len(fieldData.GetScalars().GetFloatData().GetData())
|
||||
case schemapb.DataType_Double:
|
||||
return len(fieldData.GetScalars().GetDoubleData().GetData())
|
||||
case schemapb.DataType_String:
|
||||
return len(fieldData.GetScalars().GetStringData().GetData())
|
||||
case schemapb.DataType_VarChar:
|
||||
return len(fieldData.GetScalars().GetStringData().GetData())
|
||||
case schemapb.DataType_FloatVector:
|
||||
return len(fieldData.GetVectors().GetFloatVector().GetData())
|
||||
case schemapb.DataType_BinaryVector:
|
||||
return len(fieldData.GetVectors().GetBinaryVector())
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@ -874,8 +860,6 @@ func GetData(field *schemapb.FieldData, idx int) interface{} {
|
||||
return field.GetScalars().GetFloatData().GetData()[idx]
|
||||
case schemapb.DataType_Double:
|
||||
return field.GetScalars().GetDoubleData().GetData()[idx]
|
||||
case schemapb.DataType_String:
|
||||
return field.GetScalars().GetStringData().GetData()[idx]
|
||||
case schemapb.DataType_VarChar:
|
||||
return field.GetScalars().GetStringData().GetData()[idx]
|
||||
case schemapb.DataType_FloatVector:
|
||||
|
@ -1089,7 +1089,6 @@ func TestGetDataAndGetDataSize(t *testing.T) {
|
||||
FloatArray := []float32{1.0, 2.0}
|
||||
DoubleArray := []float64{11.0, 22.0}
|
||||
VarCharArray := []string{"a", "b"}
|
||||
StringArray := []string{"c", "d"}
|
||||
BinaryVector := []byte{0x12, 0x34}
|
||||
FloatVector := []float32{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 11.0, 22.0, 33.0, 44.0, 55.0, 66.0, 77.0, 88.0}
|
||||
|
||||
@ -1101,39 +1100,18 @@ func TestGetDataAndGetDataSize(t *testing.T) {
|
||||
floatData := genFieldData(fieldName, fieldID, schemapb.DataType_Float, FloatArray, 1)
|
||||
doubleData := genFieldData(fieldName, fieldID, schemapb.DataType_Double, DoubleArray, 1)
|
||||
varCharData := genFieldData(fieldName, fieldID, schemapb.DataType_VarChar, VarCharArray, 1)
|
||||
stringData := genFieldData(fieldName, fieldID, schemapb.DataType_String, StringArray, 1)
|
||||
binVecData := genFieldData(fieldName, fieldID, schemapb.DataType_BinaryVector, BinaryVector, Dim)
|
||||
floatVecData := genFieldData(fieldName, fieldID, schemapb.DataType_FloatVector, FloatVector, Dim)
|
||||
invalidData := &schemapb.FieldData{
|
||||
Type: schemapb.DataType_None,
|
||||
}
|
||||
|
||||
t.Run("test GetDataSize", func(t *testing.T) {
|
||||
boolDataRes := GetDataSize(boolData)
|
||||
int8DataRes := GetDataSize(int8Data)
|
||||
int16DataRes := GetDataSize(int16Data)
|
||||
int32DataRes := GetDataSize(int32Data)
|
||||
int64DataRes := GetDataSize(int64Data)
|
||||
floatDataRes := GetDataSize(floatData)
|
||||
doubleDataRes := GetDataSize(doubleData)
|
||||
varCharDataRes := GetDataSize(varCharData)
|
||||
stringDataRes := GetDataSize(stringData)
|
||||
binVecDataRes := GetDataSize(binVecData)
|
||||
floatVecDataRes := GetDataSize(floatVecData)
|
||||
invalidDataRes := GetDataSize(invalidData)
|
||||
t.Run("test GetPKSize", func(t *testing.T) {
|
||||
int64DataRes := GetPKSize(int64Data)
|
||||
varCharDataRes := GetPKSize(varCharData)
|
||||
|
||||
assert.Equal(t, 2, boolDataRes)
|
||||
assert.Equal(t, 2, int8DataRes)
|
||||
assert.Equal(t, 2, int16DataRes)
|
||||
assert.Equal(t, 2, int32DataRes)
|
||||
assert.Equal(t, 2, int64DataRes)
|
||||
assert.Equal(t, 2, floatDataRes)
|
||||
assert.Equal(t, 2, doubleDataRes)
|
||||
assert.Equal(t, 2, varCharDataRes)
|
||||
assert.Equal(t, 2, stringDataRes)
|
||||
assert.Equal(t, 2*Dim/8, binVecDataRes)
|
||||
assert.Equal(t, 2*Dim, floatVecDataRes)
|
||||
assert.Equal(t, 0, invalidDataRes)
|
||||
})
|
||||
|
||||
t.Run("test GetData", func(t *testing.T) {
|
||||
@ -1145,7 +1123,6 @@ func TestGetDataAndGetDataSize(t *testing.T) {
|
||||
floatDataRes := GetData(floatData, 0)
|
||||
doubleDataRes := GetData(doubleData, 0)
|
||||
varCharDataRes := GetData(varCharData, 0)
|
||||
stringDataRes := GetData(stringData, 0)
|
||||
binVecDataRes := GetData(binVecData, 0)
|
||||
floatVecDataRes := GetData(floatVecData, 0)
|
||||
invalidDataRes := GetData(invalidData, 0)
|
||||
@ -1158,7 +1135,6 @@ func TestGetDataAndGetDataSize(t *testing.T) {
|
||||
assert.Equal(t, FloatArray[0], floatDataRes)
|
||||
assert.Equal(t, DoubleArray[0], doubleDataRes)
|
||||
assert.Equal(t, VarCharArray[0], varCharDataRes)
|
||||
assert.Equal(t, StringArray[0], stringDataRes)
|
||||
assert.ElementsMatch(t, BinaryVector[:Dim/8], binVecDataRes)
|
||||
assert.ElementsMatch(t, FloatVector[:Dim], floatVecDataRes)
|
||||
assert.Nil(t, invalidDataRes)
|
||||
|
Loading…
Reference in New Issue
Block a user