Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove field check logic for upsert #617

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading