diff --git a/internal/querynodev2/segments/mock_data.go b/internal/querynodev2/segments/mock_data.go index 6e0d7229d8e24060ae5bde543c288ca6257abf9b..97e477bcd3f49ce9737376b46e57faf0ca93eabc 100644 --- a/internal/querynodev2/segments/mock_data.go +++ b/internal/querynodev2/segments/mock_data.go @@ -1419,6 +1419,36 @@ func genFieldData(fieldName string, fieldID int64, fieldType schemapb.DataType, }, FieldId: fieldID, } + case schemapb.DataType_JSON: + fieldData = &schemapb.FieldData{ + Type: schemapb.DataType_JSON, + FieldName: fieldName, + Field: &schemapb.FieldData_Scalars{ + Scalars: &schemapb.ScalarField{ + Data: &schemapb.ScalarField_JsonData{ + JsonData: &schemapb.JSONArray{ + Data: fieldValue.([][]byte), + }, + }, + }, + }, + FieldId: fieldID, + } + case schemapb.DataType_Array: + fieldData = &schemapb.FieldData{ + Type: schemapb.DataType_Array, + FieldName: fieldName, + Field: &schemapb.FieldData_Scalars{ + Scalars: &schemapb.ScalarField{ + Data: &schemapb.ScalarField_ArrayData{ + ArrayData: &schemapb.ArrayArray{ + Data: fieldValue.([]*schemapb.ScalarField), + }, + }, + }, + }, + FieldId: fieldID, + } default: log.Error("not supported field type", zap.String("field type", fieldType.String())) } diff --git a/internal/querynodev2/segments/result_sorter.go b/internal/querynodev2/segments/result_sorter.go index 3f145ab270d511ae351a134d4bc03faa5fa94107..f488c37dab69b095fedd69c5cafd334c8f5027e4 100644 --- a/internal/querynodev2/segments/result_sorter.go +++ b/internal/querynodev2/segments/result_sorter.go @@ -61,6 +61,15 @@ func swapFieldData(field *schemapb.FieldData, i int, j int) { case *schemapb.ScalarField_StringData: data := sd.StringData.Data data[i], data[j] = data[j], data[i] + case *schemapb.ScalarField_JsonData: + data := sd.JsonData.Data + data[i], data[j] = data[j], data[i] + case *schemapb.ScalarField_ArrayData: + data := sd.ArrayData.Data + data[i], data[j] = data[j], data[i] + default: + errMsg := "undefined data type " + field.Type.String() + panic(errMsg) } case *schemapb.FieldData_Vectors: dim := int(field.GetVectors().GetDim()) diff --git a/internal/querynodev2/segments/result_test.go b/internal/querynodev2/segments/result_test.go index 2747a23ea571037f7fc5fb31846aa7ac0d30b98a..310b0015ec89c1863d4d1f82f63366b193487a38 100644 --- a/internal/querynodev2/segments/result_test.go +++ b/internal/querynodev2/segments/result_test.go @@ -558,6 +558,20 @@ func (suite *ResultSuite) TestSort() { []float32{5, 4, 3, 2, 9, 8, 7, 6}, 1), genFieldData("binary vector field", 107, schemapb.DataType_BinaryVector, []byte{5, 4, 3, 2, 9, 8, 7, 6}, 8), + genFieldData("json field", 108, schemapb.DataType_JSON, + [][]byte{[]byte("{\"5\": 5}"), []byte("{\"4\": 4}"), []byte("{\"3\": 3}"), []byte("{\"2\": 2}"), + []byte("{\"9\": 9}"), []byte("{\"8\": 8}"), []byte("{\"7\": 7}"), []byte("{\"6\": 6}")}, 1), + genFieldData("json field", 108, schemapb.DataType_Array, + []*schemapb.ScalarField{ + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{5, 6, 7}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{4, 5, 6}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{3, 4, 5}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{2, 3, 4}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{9, 10, 11}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{8, 9, 10}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{7, 8, 9}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{6, 7, 8}}}}, + }, 1), }, } @@ -573,6 +587,18 @@ func (suite *ResultSuite) TestSort() { suite.Equal([]int32{2, 3, 4, 5, 6, 7, 8, 9}, result.FieldsData[5].GetScalars().GetIntData().Data) suite.InDeltaSlice([]float32{2, 3, 4, 5, 6, 7, 8, 9}, result.FieldsData[6].GetVectors().GetFloatVector().GetData(), 10e-10) suite.Equal([]byte{2, 3, 4, 5, 6, 7, 8, 9}, result.FieldsData[7].GetVectors().GetBinaryVector()) + suite.Equal([][]byte{[]byte("{\"2\": 2}"), []byte("{\"3\": 3}"), []byte("{\"4\": 4}"), []byte("{\"5\": 5}"), + []byte("{\"6\": 6}"), []byte("{\"7\": 7}"), []byte("{\"8\": 8}"), []byte("{\"9\": 9}")}, result.FieldsData[8].GetScalars().GetJsonData().GetData()) + suite.Equal([]*schemapb.ScalarField{ + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{2, 3, 4}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{3, 4, 5}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{4, 5, 6}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{5, 6, 7}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{6, 7, 8}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{7, 8, 9}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{8, 9, 10}}}}, + {Data: &schemapb.ScalarField_IntData{IntData: &schemapb.IntArray{Data: []int32{9, 10, 11}}}}, + }, result.FieldsData[9].GetScalars().GetArrayData().GetData()) } func TestResult_MergeRequestCost(t *testing.T) {