Skip to content

Commit

Permalink
test: update case to check output dynamic key (#821)
Browse files Browse the repository at this point in the history
Signed-off-by: ThreadDao <[email protected]>
  • Loading branch information
ThreadDao authored Sep 23, 2024
1 parent 87fe6f1 commit 2cecfe4
Show file tree
Hide file tree
Showing 2 changed files with 18 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
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 output 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 2cecfe4

Please sign in to comment.