enhance: add the bytes data type for merge data and format some code (#30105)

/kind improvement

Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
SimFG 2024-01-18 22:18:55 +08:00 committed by GitHub
parent e52ce370b6
commit ddccccbcab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 72 additions and 8 deletions

View File

@ -750,7 +750,7 @@ func ValidateUsername(username string) error {
firstChar := username[0]
if !isAlpha(firstChar) {
return merr.WrapErrParameterInvalidMsg("invalid user name %s, the first character must be a letter, but got %s", username, firstChar)
return merr.WrapErrParameterInvalidMsg("invalid user name %s, the first character must be a letter, but got %s", username, string(firstChar))
}
usernameSize := len(username)

View File

@ -332,19 +332,19 @@ func (mgr *TargetManager) removePartitionFromCollectionTarget(oldTarget *Collect
func (mgr *TargetManager) getCollectionTarget(scope TargetScope, collectionID int64) *CollectionTarget {
switch scope {
case CurrentTarget:
return mgr.current.collectionTargetMap[collectionID]
return mgr.current.getCollectionTarget(collectionID)
case NextTarget:
return mgr.next.collectionTargetMap[collectionID]
return mgr.next.getCollectionTarget(collectionID)
case CurrentTargetFirst:
if current := mgr.current.collectionTargetMap[collectionID]; current != nil {
if current := mgr.current.getCollectionTarget(collectionID); current != nil {
return current
}
return mgr.next.collectionTargetMap[collectionID]
return mgr.next.getCollectionTarget(collectionID)
case NextTargetFirst:
if next := mgr.next.collectionTargetMap[collectionID]; next != nil {
if next := mgr.next.getCollectionTarget(collectionID); next != nil {
return next
}
return mgr.current.collectionTargetMap[collectionID]
return mgr.current.getCollectionTarget(collectionID)
}
return nil
}

View File

@ -423,7 +423,7 @@ func (node *QueryNode) LoadSegments(ctx context.Context, req *querypb.LoadSegmen
if err := node.lifetime.Add(merr.IsHealthy); err != nil {
return merr.Status(err), nil
}
node.lifetime.Done()
defer node.lifetime.Done()
// check target matches
if err := merr.CheckTargetID(req.GetBase()); err != nil {

View File

@ -848,6 +848,16 @@ func MergeFieldData(dst []*schemapb.FieldData, src []*schemapb.FieldData) error
} else {
dstScalar.GetJsonData().Data = append(dstScalar.GetJsonData().Data, srcScalar.JsonData.Data...)
}
case *schemapb.ScalarField_BytesData:
if dstScalar.GetBytesData() == nil {
dstScalar.Data = &schemapb.ScalarField_BytesData{
BytesData: &schemapb.BytesArray{
Data: srcScalar.BytesData.Data,
},
}
} else {
dstScalar.GetBytesData().Data = append(dstScalar.GetBytesData().Data, srcScalar.BytesData.Data...)
}
default:
log.Error("Not supported data type", zap.String("data type", srcFieldData.Type.String()))
return errors.New("unsupported data type: " + srcFieldData.Type.String())

View File

@ -1305,6 +1305,30 @@ func TestMergeFieldData(t *testing.T) {
},
},
}, 1),
{
Type: schemapb.DataType_Array,
FieldName: "bytes",
Field: &schemapb.FieldData_Scalars{
Scalars: &schemapb.ScalarField{
Data: &schemapb.ScalarField_BytesData{},
},
},
FieldId: 104,
},
{
Type: schemapb.DataType_Array,
FieldName: "bytes",
Field: &schemapb.FieldData_Scalars{
Scalars: &schemapb.ScalarField{
Data: &schemapb.ScalarField_BytesData{
BytesData: &schemapb.BytesArray{
Data: [][]byte{[]byte("hello"), []byte("world")},
},
},
},
},
FieldId: 105,
},
}
srcFields := []*schemapb.FieldData{
@ -1320,6 +1344,34 @@ func TestMergeFieldData(t *testing.T) {
},
},
}, 1),
{
Type: schemapb.DataType_Array,
FieldName: "bytes",
Field: &schemapb.FieldData_Scalars{
Scalars: &schemapb.ScalarField{
Data: &schemapb.ScalarField_BytesData{
BytesData: &schemapb.BytesArray{
Data: [][]byte{[]byte("hoo"), []byte("foo")},
},
},
},
},
FieldId: 104,
},
{
Type: schemapb.DataType_Array,
FieldName: "bytes",
Field: &schemapb.FieldData_Scalars{
Scalars: &schemapb.ScalarField{
Data: &schemapb.ScalarField_BytesData{
BytesData: &schemapb.BytesArray{
Data: [][]byte{[]byte("hoo")},
},
},
},
},
FieldId: 105,
},
}
err := MergeFieldData(dstFields, srcFields)
@ -1346,6 +1398,8 @@ func TestMergeFieldData(t *testing.T) {
},
},
dstFields[3].GetScalars().GetArrayData().Data)
assert.Equal(t, [][]byte{[]byte("hoo"), []byte("foo")}, dstFields[4].GetScalars().GetBytesData().Data)
assert.Equal(t, [][]byte{[]byte("hello"), []byte("world"), []byte("hoo")}, dstFields[5].GetScalars().GetBytesData().Data)
})
t.Run("merge with nil", func(t *testing.T) {