From 098c10922b2dcf7447a4e159de40c4ef6b27744b Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Sun, 25 Aug 2024 16:23:05 +0800 Subject: [PATCH] enhance: add some check when create collection (#35629) not support nullable==true in vector type. check it when create collection. Signed-off-by: lixinguo Co-authored-by: lixinguo --- internal/rootcoord/create_collection_task.go | 10 ++++--- .../rootcoord/create_collection_task_test.go | 28 +++++++++++++++++++ pkg/util/typeutil/schema.go | 2 +- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/internal/rootcoord/create_collection_task.go b/internal/rootcoord/create_collection_task.go index 4d55120538..8246beb4d3 100644 --- a/internal/rootcoord/create_collection_task.go +++ b/internal/rootcoord/create_collection_task.go @@ -143,8 +143,12 @@ func (t *createCollectionTask) checkMaxCollectionsPerDB(db2CollIDs map[int64][]i return check(maxColNumPerDB) } -func checkDefaultValue(schema *schemapb.CollectionSchema) error { +func checkFieldSchema(schema *schemapb.CollectionSchema) error { for _, fieldSchema := range schema.Fields { + if fieldSchema.GetNullable() && typeutil.IsVectorType(fieldSchema.GetDataType()) { + msg := fmt.Sprintf("vector type not support null, type:%s, name:%s", fieldSchema.GetDataType().String(), fieldSchema.GetName()) + return merr.WrapErrParameterInvalidMsg(msg) + } if fieldSchema.GetDefaultValue() != nil { switch fieldSchema.GetDefaultValue().Data.(type) { case *schemapb.ValueField_BoolData: @@ -228,9 +232,7 @@ func (t *createCollectionTask) validateSchema(schema *schemapb.CollectionSchema) return merr.WrapErrParameterInvalid("collection name matches schema name", "don't match", msg) } - err := checkDefaultValue(schema) - if err != nil { - log.Error("has invalid default value") + if err := checkFieldSchema(schema); err != nil { return err } diff --git a/internal/rootcoord/create_collection_task_test.go b/internal/rootcoord/create_collection_task_test.go index 6cc64bafd9..5e13b6573c 100644 --- a/internal/rootcoord/create_collection_task_test.go +++ b/internal/rootcoord/create_collection_task_test.go @@ -627,6 +627,34 @@ func Test_createCollectionTask_prepareSchema(t *testing.T) { err = task.prepareSchema() assert.Error(t, err) }) + + t.Run("vector type not support null", func(t *testing.T) { + collectionName := funcutil.GenRandomStr() + field1 := funcutil.GenRandomStr() + schema := &schemapb.CollectionSchema{ + Name: collectionName, + Description: "", + AutoID: false, + Fields: []*schemapb.FieldSchema{ + { + Name: field1, + DataType: 101, + Nullable: true, + }, + }, + } + marshaledSchema, err := proto.Marshal(schema) + assert.NoError(t, err) + task := createCollectionTask{ + Req: &milvuspb.CreateCollectionRequest{ + Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_CreateCollection}, + CollectionName: collectionName, + Schema: marshaledSchema, + }, + } + err = task.prepareSchema() + assert.Error(t, err) + }) } func Test_createCollectionTask_Prepare(t *testing.T) { diff --git a/pkg/util/typeutil/schema.go b/pkg/util/typeutil/schema.go index 350000e70d..1518b901a1 100644 --- a/pkg/util/typeutil/schema.go +++ b/pkg/util/typeutil/schema.go @@ -634,7 +634,7 @@ func AppendFieldData(dst, src []*schemapb.FieldData, idx int64) (appendSize int6 }, } } - if fieldData.GetValidData() != nil { + if len(fieldData.GetValidData()) != 0 { dst[i].ValidData = append(dst[i].ValidData, fieldData.ValidData[idx]) } dstScalar := dst[i].GetScalars()