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

fix: missing to support compact for Array type #29505

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions internal/datanode/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,24 @@
}
rst = data

case schemapb.DataType_Array:
data := &storage.ArrayFieldData{
Data: make([]*schemapb.ScalarField, 0, len(content)),
}

if len(content) > 0 {
data.ElementType = content[0].(*schemapb.ScalarField).GetArrayData().GetElementType()
}

for _, c := range content {
r, ok := c.(*schemapb.ScalarField)
if !ok {
return nil, errTransferType
}

Check warning on line 777 in internal/datanode/compactor.go

View check run for this annotation

Codecov / codecov/patch

internal/datanode/compactor.go#L776-L777

Added lines #L776 - L777 were not covered by tests
data.Data = append(data.Data, r)
}
rst = data

case schemapb.DataType_FloatVector:
data := &storage.FloatVectorFieldData{
Data: []float32{},
Expand Down
33 changes: 31 additions & 2 deletions internal/datanode/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,26 @@ func TestCompactionTaskInnerMethods(t *testing.T) {
{true, schemapb.DataType_Double, []interface{}{float64(1), float64(2)}, "valid float64"},
{true, schemapb.DataType_VarChar, []interface{}{"test1", "test2"}, "valid varChar"},
{true, schemapb.DataType_JSON, []interface{}{[]byte("{\"key\":\"value\"}"), []byte("{\"hello\":\"world\"}")}, "valid json"},
{true, schemapb.DataType_Array, []interface{}{
&schemapb.ScalarField{
Data: &schemapb.ScalarField_IntData{
IntData: &schemapb.IntArray{
Data: []int32{1, 2},
},
},
},
&schemapb.ScalarField{
Data: &schemapb.ScalarField_IntData{
IntData: &schemapb.IntArray{
Data: []int32{3, 4},
},
},
},
}, "valid array"},
{true, schemapb.DataType_FloatVector, []interface{}{[]float32{1.0, 2.0}}, "valid floatvector"},
{true, schemapb.DataType_BinaryVector, []interface{}{[]byte{255}}, "valid binaryvector"},
{true, schemapb.DataType_Float16Vector, []interface{}{[]byte{255, 255, 255, 255}}, "valid float16vector"},

{false, schemapb.DataType_Bool, []interface{}{1, 2}, "invalid bool"},
{false, schemapb.DataType_Int8, []interface{}{nil, nil}, "invalid int8"},
{false, schemapb.DataType_Int16, []interface{}{nil, nil}, "invalid int16"},
Expand All @@ -114,9 +131,21 @@ func TestCompactionTaskInnerMethods(t *testing.T) {
{false, schemapb.DataType_FloatVector, []interface{}{nil, nil}, "invalid floatvector"},
{false, schemapb.DataType_BinaryVector, []interface{}{nil, nil}, "invalid binaryvector"},
{false, schemapb.DataType_Float16Vector, []interface{}{nil, nil}, "invalid float16vector"},
{false, schemapb.DataType_None, nil, "invalid data type"},
}

// make sure all new data types missed to handle would throw unexpected error
// todo(yah01): enable this after the BF16 vector type ready
// for typeName, typeValue := range schemapb.DataType_value {
// tests = append(tests, struct {
// isvalid bool

// tp schemapb.DataType
// content []interface{}

// description string
// }{false, schemapb.DataType(typeValue), []interface{}{nil, nil}, "invalid " + typeName})
// }

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
if test.isvalid {
Expand All @@ -125,7 +154,7 @@ func TestCompactionTaskInnerMethods(t *testing.T) {
assert.Equal(t, 2, fd.RowNum())
} else {
fd, err := interface2FieldData(test.tp, test.content, 2)
assert.Error(t, err)
assert.ErrorIs(t, err, errTransferType)
assert.Nil(t, fd)
}
})
Expand Down
Loading