mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-30 10:59:32 +08:00
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:
parent
66ed289a85
commit
80a9efd96d
@ -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 {
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user