mirror of https://github.com/milvus-io/milvus.git
fix: [restful]vector field cannot be empty while insert (#30871)
issue: #30870 did a check whether the vector field is empty in advance Signed-off-by: PowderLi <min.li@zilliz.com>pull/30788/head
parent
af315539d4
commit
6548182a4a
|
@ -204,6 +204,9 @@ func checkAndSetData(body string, collSchema *schemapb.CollectionSchema) (error,
|
|||
|
||||
switch fieldType {
|
||||
case schemapb.DataType_FloatVector:
|
||||
if dataString == "" {
|
||||
return merr.WrapErrParameterInvalid(schemapb.DataType_name[int32(fieldType)], "", "missing vector field: "+fieldName), reallyDataArray
|
||||
}
|
||||
var vectorArray []float32
|
||||
err := json.Unmarshal([]byte(dataString), &vectorArray)
|
||||
if err != nil {
|
||||
|
@ -211,6 +214,9 @@ func checkAndSetData(body string, collSchema *schemapb.CollectionSchema) (error,
|
|||
}
|
||||
reallyData[fieldName] = vectorArray
|
||||
case schemapb.DataType_BinaryVector:
|
||||
if dataString == "" {
|
||||
return merr.WrapErrParameterInvalid(schemapb.DataType_name[int32(fieldType)], "", "missing vector field: "+fieldName), reallyDataArray
|
||||
}
|
||||
vectorStr := gjson.Get(data.Raw, fieldName).Raw
|
||||
var vectorArray []byte
|
||||
err := json.Unmarshal([]byte(vectorStr), &vectorArray)
|
||||
|
@ -219,6 +225,9 @@ func checkAndSetData(body string, collSchema *schemapb.CollectionSchema) (error,
|
|||
}
|
||||
reallyData[fieldName] = vectorArray
|
||||
case schemapb.DataType_Float16Vector:
|
||||
if dataString == "" {
|
||||
return merr.WrapErrParameterInvalid(schemapb.DataType_name[int32(fieldType)], "", "missing vector field: "+fieldName), reallyDataArray
|
||||
}
|
||||
vectorStr := gjson.Get(data.Raw, fieldName).Raw
|
||||
var vectorArray []byte
|
||||
err := json.Unmarshal([]byte(vectorStr), &vectorArray)
|
||||
|
@ -227,6 +236,9 @@ func checkAndSetData(body string, collSchema *schemapb.CollectionSchema) (error,
|
|||
}
|
||||
reallyData[fieldName] = vectorArray
|
||||
case schemapb.DataType_BFloat16Vector:
|
||||
if dataString == "" {
|
||||
return merr.WrapErrParameterInvalid(schemapb.DataType_name[int32(fieldType)], "", "missing vector field: "+fieldName), reallyDataArray
|
||||
}
|
||||
vectorStr := gjson.Get(data.Raw, fieldName).Raw
|
||||
var vectorArray []byte
|
||||
err := json.Unmarshal([]byte(vectorStr), &vectorArray)
|
||||
|
|
|
@ -416,6 +416,57 @@ func TestInsertWithDynamicFields(t *testing.T) {
|
|||
assert.Equal(t, "{\"classified\":false,\"id\":0}", string(fieldsData[len(fieldsData)-1].GetScalars().GetJsonData().GetData()[0]))
|
||||
}
|
||||
|
||||
func TestInsertWithoutVector(t *testing.T) {
|
||||
body := "{\"data\": {}}"
|
||||
var err error
|
||||
primaryField := generatePrimaryField(schemapb.DataType_Int64)
|
||||
primaryField.AutoID = true
|
||||
floatVectorField := generateVectorFieldSchema(schemapb.DataType_FloatVector)
|
||||
floatVectorField.Name = "floatVector"
|
||||
binaryVectorField := generateVectorFieldSchema(schemapb.DataType_BinaryVector)
|
||||
binaryVectorField.Name = "binaryVector"
|
||||
float16VectorField := generateVectorFieldSchema(schemapb.DataType_Float16Vector)
|
||||
float16VectorField.Name = "float16Vector"
|
||||
bfloat16VectorField := generateVectorFieldSchema(schemapb.DataType_BFloat16Vector)
|
||||
bfloat16VectorField.Name = "bfloat16Vector"
|
||||
err, _ = checkAndSetData(body, &schemapb.CollectionSchema{
|
||||
Name: DefaultCollectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
&primaryField, &floatVectorField,
|
||||
},
|
||||
EnableDynamicField: true,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, true, strings.HasPrefix(err.Error(), "missing vector field"))
|
||||
err, _ = checkAndSetData(body, &schemapb.CollectionSchema{
|
||||
Name: DefaultCollectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
&primaryField, &binaryVectorField,
|
||||
},
|
||||
EnableDynamicField: true,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, true, strings.HasPrefix(err.Error(), "missing vector field"))
|
||||
err, _ = checkAndSetData(body, &schemapb.CollectionSchema{
|
||||
Name: DefaultCollectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
&primaryField, &float16VectorField,
|
||||
},
|
||||
EnableDynamicField: true,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, true, strings.HasPrefix(err.Error(), "missing vector field"))
|
||||
err, _ = checkAndSetData(body, &schemapb.CollectionSchema{
|
||||
Name: DefaultCollectionName,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
&primaryField, &bfloat16VectorField,
|
||||
},
|
||||
EnableDynamicField: true,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, true, strings.HasPrefix(err.Error(), "missing vector field"))
|
||||
}
|
||||
|
||||
func TestInsertWithInt64(t *testing.T) {
|
||||
arrayFieldName := "array-int64"
|
||||
body := "{\"data\": {\"book_id\": 9999999999999999, \"book_intro\": [0.1, 0.2], \"word_count\": 2, \"" + arrayFieldName + "\": [9999999999999999]}}"
|
||||
|
|
Loading…
Reference in New Issue