fix: skip to check auto id when inserting data (#32775)

/kind improvement
issue: https://github.com/milvus-io/milvus/issues/32591
related pr: #32592

Signed-off-by: SimFG <bang.fu@zilliz.com>
pull/32797/head
SimFG 2024-05-07 10:17:30 +08:00 committed by GitHub
parent a5d1135512
commit 48fb8310ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 94 additions and 0 deletions

View File

@ -1147,6 +1147,10 @@ func fillFieldsDataBySchema(schema *schemapb.CollectionSchema, insertMsg *msgstr
if !fieldSchema.AutoID {
requiredFieldsNum++
}
if fieldSchema.AutoID && Params.ProxyCfg.SkipAutoIDCheck.GetAsBool() {
requiredFieldsNum++
}
// if has no field pass in, consider use default value
// so complete it with field schema
if _, ok := dataNameSet[fieldSchema.GetName()]; !ok {

View File

@ -28,6 +28,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
@ -1122,6 +1123,8 @@ func Test_isPartitionIsLoaded(t *testing.T) {
}
func Test_InsertTaskfillFieldsDataBySchema(t *testing.T) {
paramtable.Init()
log.Info("Test_InsertTaskfillFieldsDataBySchema", zap.Bool("enable", Params.ProxyCfg.SkipAutoIDCheck.GetAsBool()))
var err error
// schema is empty, though won't happen in system
@ -1399,6 +1402,93 @@ func Test_InsertTaskfillFieldsDataBySchema(t *testing.T) {
err = fillFieldsDataBySchema(case8.schema, case8.insertMsg)
assert.ErrorIs(t, merr.ErrParameterInvalid, err)
assert.Equal(t, len(case8.insertMsg.FieldsData), 0)
// skip the auto id
case9 := insertTask{
schema: &schemapb.CollectionSchema{
Name: "TestInsertTask_fillFieldsDataBySchema",
Description: "TestInsertTask_fillFieldsDataBySchema",
AutoID: false,
Fields: []*schemapb.FieldSchema{
{
Name: "a",
AutoID: true,
IsPrimaryKey: true,
DataType: schemapb.DataType_Int64,
},
{
Name: "b",
AutoID: false,
DataType: schemapb.DataType_Int64,
},
},
},
insertMsg: &BaseInsertTask{
InsertRequest: msgpb.InsertRequest{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_Insert,
},
FieldsData: []*schemapb.FieldData{
{
FieldName: "a",
Type: schemapb.DataType_Int64,
},
{
FieldName: "b",
Type: schemapb.DataType_Int64,
},
},
},
},
}
err = fillFieldsDataBySchema(case9.schema, case9.insertMsg)
assert.ErrorIs(t, merr.ErrParameterInvalid, err)
assert.Equal(t, len(case9.insertMsg.FieldsData), 2)
paramtable.Get().Save(Params.ProxyCfg.SkipAutoIDCheck.Key, "true")
case10 := insertTask{
schema: &schemapb.CollectionSchema{
Name: "TestInsertTask_fillFieldsDataBySchema",
Description: "TestInsertTask_fillFieldsDataBySchema",
AutoID: false,
Fields: []*schemapb.FieldSchema{
{
Name: "a",
AutoID: true,
IsPrimaryKey: true,
DataType: schemapb.DataType_Int64,
},
{
Name: "b",
AutoID: false,
DataType: schemapb.DataType_Int64,
},
},
},
insertMsg: &BaseInsertTask{
InsertRequest: msgpb.InsertRequest{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_Insert,
},
FieldsData: []*schemapb.FieldData{
{
FieldName: "a",
Type: schemapb.DataType_Int64,
},
{
FieldName: "b",
Type: schemapb.DataType_Int64,
},
},
},
},
}
err = fillFieldsDataBySchema(case10.schema, case10.insertMsg)
assert.NoError(t, err)
assert.Equal(t, len(case10.insertMsg.FieldsData), 2)
paramtable.Get().Reset(Params.ProxyCfg.SkipAutoIDCheck.Key)
}
func Test_InsertTaskCheckPrimaryFieldData(t *testing.T) {