From f336b2d67224dd1d3d60257348b795df3664f6de Mon Sep 17 00:00:00 2001 From: congqixia Date: Tue, 21 May 2024 14:33:39 +0800 Subject: [PATCH] fix: Check schema without vector field in proxy (#33211) Related to #33199 Signed-off-by: Congqi Xia --- internal/proxy/task.go | 7 ++++++- internal/proxy/task_test.go | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/proxy/task.go b/internal/proxy/task.go index 4167a04ce3..7aa1457fd1 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -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 diff --git a/internal/proxy/task_test.go b/internal/proxy/task_test.go index 161f5b1bf9..33fb1bfaed 100644 --- a/internal/proxy/task_test.go +++ b/internal/proxy/task_test.go @@ -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