fix: Check schema without vector field in proxy (#33211)

Related to #33199

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/33259/head
congqixia 2024-05-21 14:33:39 +08:00 committed by GitHub
parent 2013d97243
commit f336b2d672
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -293,10 +293,15 @@ func (t *createCollectionTask) PreExecute(ctx context.Context) error {
return fmt.Errorf("maximum field's number should be limited to %d", Params.ProxyCfg.MaxFieldNum.GetAsInt())
}
if len(typeutil.GetVectorFieldSchemas(t.schema)) > Params.ProxyCfg.MaxVectorFieldNum.GetAsInt() {
vectorFields := len(typeutil.GetVectorFieldSchemas(t.schema))
if vectorFields > Params.ProxyCfg.MaxVectorFieldNum.GetAsInt() {
return fmt.Errorf("maximum vector field's number should be limited to %d", Params.ProxyCfg.MaxVectorFieldNum.GetAsInt())
}
if vectorFields == 0 {
return merr.WrapErrParameterInvalidMsg("schema does not contain vector field")
}
// validate collection name
if err := validateCollectionName(t.schema.Name); err != nil {
return err

View File

@ -754,6 +754,25 @@ func TestCreateCollectionTask(t *testing.T) {
err = task.PreExecute(ctx)
assert.Error(t, err)
// without vector field
schema = &schemapb.CollectionSchema{
Name: collectionName,
Description: "",
AutoID: false,
Fields: []*schemapb.FieldSchema{
{
Name: "id",
DataType: schemapb.DataType_Int64,
IsPrimaryKey: true,
},
},
}
noVectorSchema, err := proto.Marshal(schema)
assert.NoError(t, err)
task.CreateCollectionRequest.Schema = noVectorSchema
err = task.PreExecute(ctx)
assert.Error(t, err)
task.CreateCollectionRequest = reqBackup
// validateCollectionName