fix: not check nullable and default value in pk field (#35987)

#35926

Signed-off-by: lixinguo <xinguo.li@zilliz.com>
Co-authored-by: lixinguo <xinguo.li@zilliz.com>
This commit is contained in:
smellthemoon 2024-09-05 11:27:04 +08:00 committed by GitHub
parent 66ed289a85
commit 80a9efd96d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 0 deletions

View File

@ -153,7 +153,15 @@ func checkFieldSchema(schema *schemapb.CollectionSchema) error {
msg := fmt.Sprintf("vector type not support null, type:%s, name:%s", fieldSchema.GetDataType().String(), fieldSchema.GetName())
return merr.WrapErrParameterInvalidMsg(msg)
}
if fieldSchema.GetNullable() && fieldSchema.IsPrimaryKey {
msg := fmt.Sprintf("primary field not support null, type:%s, name:%s", fieldSchema.GetDataType().String(), fieldSchema.GetName())
return merr.WrapErrParameterInvalidMsg(msg)
}
if fieldSchema.GetDefaultValue() != nil {
if fieldSchema.IsPrimaryKey {
msg := fmt.Sprintf("primary field not support default_value, type:%s, name:%s", fieldSchema.GetDataType().String(), fieldSchema.GetName())
return merr.WrapErrParameterInvalidMsg(msg)
}
switch fieldSchema.GetDefaultValue().Data.(type) {
case *schemapb.ValueField_BoolData:
if fieldSchema.GetDataType() != schemapb.DataType_Bool {

View File

@ -334,6 +334,54 @@ func Test_createCollectionTask_validateSchema(t *testing.T) {
assert.Error(t, err)
})
t.Run("primary field set nullable", func(t *testing.T) {
collectionName := funcutil.GenRandomStr()
task := createCollectionTask{
Req: &milvuspb.CreateCollectionRequest{
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_CreateCollection},
CollectionName: collectionName,
},
}
schema := &schemapb.CollectionSchema{
Name: collectionName,
Fields: []*schemapb.FieldSchema{
{
Name: "pk",
IsPrimaryKey: true,
Nullable: true,
},
},
}
err := task.validateSchema(schema)
assert.Error(t, err)
})
t.Run("primary field set default_value", func(t *testing.T) {
collectionName := funcutil.GenRandomStr()
task := createCollectionTask{
Req: &milvuspb.CreateCollectionRequest{
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_CreateCollection},
CollectionName: collectionName,
},
}
schema := &schemapb.CollectionSchema{
Name: collectionName,
Fields: []*schemapb.FieldSchema{
{
Name: "pk",
IsPrimaryKey: true,
DefaultValue: &schemapb.ValueField{
Data: &schemapb.ValueField_LongData{
LongData: 1,
},
},
},
},
}
err := task.validateSchema(schema)
assert.Error(t, err)
})
t.Run("has system fields", func(t *testing.T) {
collectionName := funcutil.GenRandomStr()
task := createCollectionTask{