If autoID enabled, check to make sure user didn't specify autoID field (#19943)

Signed-off-by: xiaofan-luan <xiaofan.luan@zilliz.com>

Signed-off-by: xiaofan-luan <xiaofan.luan@zilliz.com>
This commit is contained in:
Xiaofan 2022-10-21 19:03:27 +08:00 committed by GitHub
parent 1b7968557c
commit 7d2ba60412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -144,6 +144,10 @@ func (it *insertTask) checkPrimaryFieldData() error {
return err
}
} else {
// check primary key data not exist
if typeutil.IsPrimaryFieldDataExist(it.GetFieldsData(), primaryFieldSchema) {
return fmt.Errorf("can not assign primary field data when auto id enabled %v", primaryFieldSchema.Name)
}
// if autoID == true, currently only support autoID for int64 PrimaryField
primaryFieldData, err = autoGenPrimaryFieldData(primaryFieldSchema, it.RowIDs)
if err != nil {

View File

@ -556,6 +556,21 @@ func GetPrimaryFieldData(datas []*schemapb.FieldData, primaryFieldSchema *schema
return primaryFieldData, nil
}
func IsPrimaryFieldDataExist(datas []*schemapb.FieldData, primaryFieldSchema *schemapb.FieldSchema) bool {
primaryFieldID := primaryFieldSchema.FieldID
primaryFieldName := primaryFieldSchema.Name
var primaryFieldData *schemapb.FieldData
for _, field := range datas {
if field.FieldId == primaryFieldID || field.FieldName == primaryFieldName {
primaryFieldData = field
break
}
}
return primaryFieldData != nil
}
func AppendIDs(dst *schemapb.IDs, src *schemapb.IDs, idx int) {
switch src.IdField.(type) {
case *schemapb.IDs_IntId: