enhance: add some check when create collection (#35629)

not support nullable==true in vector type. check it when create
collection.

Signed-off-by: lixinguo <xinguo.li@zilliz.com>
Co-authored-by: lixinguo <xinguo.li@zilliz.com>
pull/35688/head
smellthemoon 2024-08-25 16:23:05 +08:00 committed by GitHub
parent 0dc5e89007
commit 098c10922b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 5 deletions

View File

@ -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
}

View File

@ -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) {

View File

@ -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()