From 6eef3441b8c4dd7bcc394d7baf79e0960ef52980 Mon Sep 17 00:00:00 2001 From: ThreadDao Date: Mon, 23 Sep 2024 11:13:06 +0800 Subject: [PATCH] test: [cherry-pick] update case to check output dynamic key (#822) Signed-off-by: ThreadDao --- test/common/response_check.go | 13 +++++++--- test/testcases/insert_test.go | 46 +++++++++++++++++++++++++++++++++++ test/testcases/query_test.go | 12 ++++++--- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/test/common/response_check.go b/test/common/response_check.go index 1a5840dc..2d0b8531 100644 --- a/test/common/response_check.go +++ b/test/common/response_check.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "log" + "reflect" "strings" "testing" @@ -155,9 +156,15 @@ func EqualColumn(t *testing.T, columnA entity.Column, columnB entity.Column) { case entity.FieldTypeVarChar: require.ElementsMatch(t, columnA.(*entity.ColumnVarChar).Data(), columnB.(*entity.ColumnVarChar).Data()) case entity.FieldTypeJSON: - log.Printf("columnA: %s", columnA.(*entity.ColumnJSONBytes).Data()) - log.Printf("columnB: %s", columnB.(*entity.ColumnJSONBytes).Data()) - require.ElementsMatch(t, columnA.(*entity.ColumnJSONBytes).Data(), columnB.(*entity.ColumnJSONBytes).Data()) + log.Printf("columnA: %s", columnA.FieldData()) + log.Printf("columnB: %s", columnB.FieldData()) + require.Equal(t, reflect.TypeOf(columnA), reflect.TypeOf(columnB)) + switch columnA.(type) { + case *entity.ColumnDynamic: + require.ElementsMatch(t, columnA.(*entity.ColumnDynamic).Data(), columnB.(*entity.ColumnDynamic).Data()) + case *entity.ColumnJSONBytes: + require.ElementsMatch(t, columnA.(*entity.ColumnJSONBytes).Data(), columnB.(*entity.ColumnJSONBytes).Data()) + } case entity.FieldTypeFloatVector: require.ElementsMatch(t, columnA.(*entity.ColumnFloatVector).Data(), columnB.(*entity.ColumnFloatVector).Data()) case entity.FieldTypeBinaryVector: diff --git a/test/testcases/insert_test.go b/test/testcases/insert_test.go index b35375a3..00f44b07 100644 --- a/test/testcases/insert_test.go +++ b/test/testcases/insert_test.go @@ -415,6 +415,52 @@ func TestInsertDynamicFieldData(t *testing.T) { } +// dynamic field name is same as other field name +func TestInsertRepeatedDynamicField(t *testing.T) { + ctx := createContext(t, time.Second*common.DefaultTimeout) + + // connect + mc := createMilvusClient(ctx, t) + nb := 1000 + + // create collection enable dynamic field + schema := common.GenSchema(common.GenRandomString(6), false, common.GenDefaultFields(false), common.WithEnableDynamicField(true)) + createCustomerCollection(ctx, t, mc, schema, 1) + + // insert column with repeated dynamic field name + intColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, nb, common.DefaultDim) + dynamicColumn := common.GenColumnData(nb, nb, entity.FieldTypeInt64, common.DefaultFloatFieldName) + _, errInsert := mc.Insert(ctx, schema.CollectionName, "", intColumn, floatColumn, vecColumn, dynamicColumn) + common.CheckErr(t, errInsert, false, "duplicated column float found") + + // insert rows with repeated dynamic field name + type DynamicRows struct { + Float float32 `json:"float" milvus:"name:float"` + } + + type dataRows struct { + Int64 int64 `json:"int64" milvus:"name:int64"` + Float float32 `json:"float" milvus:"name:float"` + FloatVec []float32 `json:"floatVec" milvus:"name:floatVec"` + DynamicRows + } + rows := make([]interface{}, 0, 100) + for i := 0; i < 100; i++ { + row := dataRows{ + Int64: int64(i), + Float: float32(i), + FloatVec: common.GenFloatVector(common.DefaultDim), + DynamicRows: DynamicRows{ + Float: 0.0, + }, + } + rows = append(rows, row) + } + + _, err := mc.InsertRows(context.Background(), schema.CollectionName, "", rows) + common.CheckErr(t, err, false, "column has duplicated name: float when parsing field: DynamicRows") +} + // test insert array column with empty data func TestInsertEmptyArray(t *testing.T) { ctx := createContext(t, time.Second*common.DefaultTimeout) diff --git a/test/testcases/query_test.go b/test/testcases/query_test.go index 2833fad5..59148e84 100644 --- a/test/testcases/query_test.go +++ b/test/testcases/query_test.go @@ -984,12 +984,16 @@ func TestQueryJsonDynamicExpr(t *testing.T) { // verify output fields and count, dynamicNumber value common.CheckOutputFields(t, queryRes, []string{common.DefaultIntFieldName, common.DefaultJSONFieldName, common.DefaultDynamicNumberField}) require.Equal(t, 10, queryRes.GetColumn(common.DefaultJSONFieldName).Len()) + + // verify only dynamic part key: common.DefaultDynamicNumberField dynamicNumColumn := queryRes.GetColumn(common.DefaultDynamicNumberField) - var numberData []int64 - for i := 0; i < dynamicNumColumn.Len(); i++ { - line, _ := dynamicNumColumn.GetAsInt64(i) - numberData = append(numberData, line) + numberValues := make([]int32, 0, 10) + for i := 0; i < 10; i++ { + numberValues = append(numberValues, int32(i)) } + _expColumn := common.MergeColumnsToDynamic(10, common.GenDynamicFieldData(0, 10)[:1], common.DefaultDynamicFieldName) + expColumn := entity.NewColumnDynamic(_expColumn, common.DefaultDynamicNumberField) + common.EqualColumn(t, dynamicNumColumn, expColumn) } // test query and output both json and dynamic field