diff --git a/client/insert.go b/client/insert.go index 49d4436e..91b7c0ff 100644 --- a/client/insert.go +++ b/client/insert.go @@ -362,46 +362,10 @@ func (c *GrpcClient) Upsert(ctx context.Context, collName string, partitionName if err != nil { return nil, err } - mNameField := make(map[string]*entity.Field) - for _, field := range coll.Schema.Fields { - mNameField[field.Name] = field - } - mNameColumn := make(map[string]entity.Column) - for _, column := range columns { - mNameColumn[column.Name()] = column - l := column.Len() - if rowSize == 0 { - rowSize = l - } else { - if rowSize != l { - return nil, errors.New("column size not match") - } - } - field, has := mNameField[column.Name()] - if !has { - return nil, fmt.Errorf("field %s does not exist in collection %s", column.Name(), collName) - } - if column.Type() != field.DataType { - return nil, fmt.Errorf("param column %s has type %v but collection field definition is %v", column.Name(), column.FieldData(), field.DataType) - } - if field.DataType == entity.FieldTypeFloatVector || field.DataType == entity.FieldTypeBinaryVector { - dim := 0 - switch column := column.(type) { - case *entity.ColumnFloatVector: - dim = column.Dim() - case *entity.ColumnBinaryVector: - dim = column.Dim() - } - if fmt.Sprintf("%d", dim) != field.TypeParams[entity.TypeParamDim] { - return nil, fmt.Errorf("params column %s vector dim %d not match collection definition, which has dim of %s", field.Name, dim, field.TypeParams[entity.TypeParamDim]) - } - } - } - for _, field := range coll.Schema.Fields { - _, has := mNameColumn[field.Name] - if !has && !field.AutoID { - return nil, fmt.Errorf("field %s not passed", field.Name) - } + + fieldsData, rowSize, err := c.processInsertColumns(coll.Schema, columns...) + if err != nil { + return nil, err } // 2. do upsert request @@ -409,12 +373,11 @@ func (c *GrpcClient) Upsert(ctx context.Context, collName string, partitionName DbName: "", // reserved CollectionName: collName, PartitionName: partitionName, + FieldsData: fieldsData, } req.NumRows = uint32(rowSize) - for _, column := range columns { - req.FieldsData = append(req.FieldsData, column.FieldData()) - } + resp, err := c.Service.Upsert(ctx, req) if err != nil { return nil, err