Skip to content

Commit

Permalink
test: [cherry-pick] update case to check output dynamic key (#822)
Browse files Browse the repository at this point in the history
Signed-off-by: ThreadDao <yufen.zong@zilliz.com>
  • Loading branch information
ThreadDao authored Sep 23, 2024
1 parent 99efce9 commit 6eef344
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
13 changes: 10 additions & 3 deletions test/common/response_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -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:
Expand Down
46 changes: 46 additions & 0 deletions test/testcases/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions test/testcases/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6eef344

Please sign in to comment.