Skip to content

Commit

Permalink
Remove field check logic for upsert
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia committed Nov 8, 2023
1 parent 94c4107 commit ebd17cd
Showing 1 changed file with 6 additions and 43 deletions.
49 changes: 6 additions & 43 deletions client/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,59 +362,22 @@ 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
req := &milvuspb.UpsertRequest{
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
Expand Down

0 comments on commit ebd17cd

Please sign in to comment.