Repository: milvus-io/milvus-sdk-go
Pull request #469 (2023-05-25 10:24:31)

[2.2.x] Improve ResultSet & Column Get methods
- Add GetAs(Int|Double|String|Bool) methods for all column
- Fix some warning in test cases
- Use GetColumn and GetAsXXX methods in dynamic schema example

/kind improvement


sre-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/469#" title="Author self-approved">congqixia</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/v2.2.x/OWNERS)~~ [congqixia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
sre-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/469#" title="Author self-approved">congqixia</a>*, *<a href="https://github.com/milvus-io/milvus-sdk-go/pull/469#pullrequestreview-1443612454" title="LGTM">yah01</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=milvus-io%2Fmilvus-sdk-go).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/milvus-io/milvus-sdk-go/blob/v2.2.x/OWNERS)~~ [congqixia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/client/client.go b/client/client.go
index c9d7635..8389b0e 100644
--- a/client/client.go
+++ b/client/client.go
@@ -207,8 +207,10 @@ type SearchResult struct {
 	Err         error         // search error if any
 }
 
+// ResultSet is an alias type for column slice.
 type ResultSet []entity.Column
 
+// GetColumn returns column with provided field name.
 func (rs ResultSet) GetColumn(fieldName string) entity.Column {
 	for _, column := range rs {
 		if column.Name() == fieldName {
diff --git a/client/partition.go b/client/partition.go
index 8a16175..0ed1762 100644
--- a/client/partition.go
+++ b/client/partition.go
@@ -161,7 +161,7 @@ func (c *GrpcClient) LoadPartitions(ctx context.Context, collName string, partit
 	for _, partitionName := range partitionNames {
 		id, has := m[partitionName]
 		if !has {
-			return fmt.Errorf("Collection %s does not has partitions %s", collName, partitionName)
+			return fmt.Errorf("collection %s does not has partitions %s", collName, partitionName)
 		}
 		ids[id] = struct{}{}
 	}
diff --git a/entity/columns.go b/entity/columns.go
index 8e5a38a..2a7b0c0 100644
--- a/entity/columns.go
+++ b/entity/columns.go
@@ -30,6 +30,29 @@ type Column interface {
 	FieldData() *schema.FieldData
 	AppendValue(interface{}) error
 	Get(int) (interface{}, error)
+	GetAsInt64(int) (int64, error)
+	GetAsString(int) (string, error)
+	GetAsDouble(int) (float64, error)
+	GetAsBool(int) (bool, error)
+}
+
+// ColumnBase adds conversion methods support for fixed-type columns.
+type ColumnBase struct{}
+
+func (b ColumnBase) GetAsInt64(_ int) (int64, error) {
+	return 0, errors.New("conversion between fixed-type column not support")
+}
+
+func (b ColumnBase) GetAsString(_ int) (string, error) {
+	return "", errors.New("conversion between fixed-type column not support")
+}
+
+func (b ColumnBase) GetAsDouble(_ int) (float64, error) {
+	return 0, errors.New("conversion between fixed-type column not support")
+}
+
+func (b ColumnBase) GetAsBool(_ int) (bool, error) {
+	return false, errors.New("conversion between fixed-type column not support")
 }
 
 // Vector interface vector used int search
diff --git a/entity/columns_conversion.go b/entity/columns_conversion.go
new file mode 100644
index 0000000..7910cae
--- /dev/null
+++ b/entity/columns_conversion.go
@@ -0,0 +1,37 @@
+package entity
+
+func (c *ColumnInt8) GetAsInt64(idx int) (int64, error) {
+	v, err := c.ValueByIdx(idx)
+	return int64(v), err
+}
+
+func (c *ColumnInt16) GetAsInt64(idx int) (int64, error) {
+	v, err := c.ValueByIdx(idx)
+	return int64(v), err
+}
+
+func (c *ColumnInt32) GetAsInt64(idx int) (int64, error) {
+	v, err := c.ValueByIdx(idx)
+	return int64(v), err
+}
+
+func (c *ColumnInt64) GetAsInt64(idx int) (int64, error) {
+	return c.ValueByIdx(idx)
+}
+
+func (c *ColumnString) GetAsString(idx int) (string, error) {
+	return c.ValueByIdx(idx)
+}
+
+func (c *ColumnFloat) GetAsDouble(idx int) (float64, error) {
+	v, err := c.ValueByIdx(idx)
+	return float64(v), err
+}
+
+func (c *ColumnDouble) GetAsDouble(idx int) (float64, error) {
+	return c.ValueByIdx(idx)
+}
+
+func (c *ColumnBool) GetAsBool(idx int) (bool, error) {
+	return c.ValueByIdx(idx)
+}
diff --git a/entity/columns_dynamic.go b/entity/columns_dynamic.go
index e4a0183..a865b66 100644
--- a/entity/columns_dynamic.go
+++ b/entity/columns_dynamic.go
@@ -33,7 +33,21 @@ func (c *ColumnDynamic) Name() string {
 	return c.outputField
 }
 
-func (c *ColumnDynamic) GetInt64(idx int) (int64, error) {
+// Get returns element at idx as interface{}.
+// Overrides internal json column behavior, returns raw json data.
+func (c *ColumnDynamic) Get(idx int) (interface{}, error) {
+	bs, err := c.ColumnJSONBytes.ValueByIdx(idx)
+	if err != nil {
+		return 0, err
+	}
+	r := gjson.GetBytes(bs, c.outputField)
+	if !r.Exists() {
+		return 0, errors.New("column not has value")
+	}
+	return r.Raw, nil
+}
+
+func (c *ColumnDynamic) GetAsInt64(idx int) (int64, error) {
 	bs, err := c.ColumnJSONBytes.ValueByIdx(idx)
 	if err != nil {
 		return 0, err
@@ -48,7 +62,7 @@ func (c *ColumnDynamic) GetInt64(idx int) (int64, error) {
 	return r.Int(), nil
 }
 
-func (c *ColumnDynamic) GetString(idx int) (string, error) {
+func (c *ColumnDynamic) GetAsString(idx int) (string, error) {
 	bs, err := c.ColumnJSONBytes.ValueByIdx(idx)
 	if err != nil {
 		return "", err
@@ -63,7 +77,7 @@ func (c *ColumnDynamic) GetString(idx int) (string, error) {
 	return r.String(), nil
 }
 
-func (c *ColumnDynamic) GetBool(idx int) (bool, error) {
+func (c *ColumnDynamic) GetAsBool(idx int) (bool, error) {
 	bs, err := c.ColumnJSONBytes.ValueByIdx(idx)
 	if err != nil {
 		return false, err
@@ -78,7 +92,7 @@ func (c *ColumnDynamic) GetBool(idx int) (bool, error) {
 	return r.Bool(), nil
 }
 
-func (c *ColumnDynamic) GetDouble(idx int) (float64, error) {
+func (c *ColumnDynamic) GetAsDouble(idx int) (float64, error) {
 	bs, err := c.ColumnJSONBytes.ValueByIdx(idx)
 	if err != nil {
 		return 0, err
diff --git a/entity/columns_json.go b/entity/columns_json.go
index 41c7919..8cb2226 100644
--- a/entity/columns_json.go
+++ b/entity/columns_json.go
@@ -12,6 +12,7 @@ var _ (Column) = (*ColumnJSONBytes)(nil)
 // ColumnJSONBytes column type for JSON.
 // all items are marshaled json bytes.
 type ColumnJSONBytes struct {
+	ColumnBase
 	name      string
 	values    [][]byte
 	isDynamic bool
@@ -40,6 +41,14 @@ func (c *ColumnJSONBytes) Get(idx int) (interface{}, error) {
 	return c.values[idx], nil
 }
 
+func (c *ColumnJSONBytes) GetAsString(idx int) (string, error) {
+	bs, err := c.ValueByIdx(idx)
+	if err != nil {
+		return "", err
+	}
+	return string(bs), nil
+}
+
 // FieldData return column data mapped to schema.FieldData.
 func (c *ColumnJSONBytes) FieldData() *schema.FieldData {
 	fd := &schema.FieldData{
diff --git a/entity/columns_scalar_gen.go b/entity/columns_scalar_gen.go
index 14869e8..d375ae5 100755
--- a/entity/columns_scalar_gen.go
+++ b/entity/columns_scalar_gen.go
@@ -12,6 +12,7 @@ import (
 
 // ColumnBool generated columns type for Bool
 type ColumnBool struct {
+	ColumnBase
 	name   string
 	values []bool
 }
@@ -98,6 +99,7 @@ func NewColumnBool(name string, values []bool) *ColumnBool {
 
 // ColumnInt8 generated columns type for Int8
 type ColumnInt8 struct {
+	ColumnBase
 	name   string
 	values []int8
 }
@@ -184,6 +186,7 @@ func NewColumnInt8(name string, values []int8) *ColumnInt8 {
 
 // ColumnInt16 generated columns type for Int16
 type ColumnInt16 struct {
+	ColumnBase
 	name   string
 	values []int16
 }
@@ -270,6 +273,7 @@ func NewColumnInt16(name string, values []int16) *ColumnInt16 {
 
 // ColumnInt32 generated columns type for Int32
 type ColumnInt32 struct {
+	ColumnBase
 	name   string
 	values []int32
 }
@@ -356,6 +360,7 @@ func NewColumnInt32(name string, values []int32) *ColumnInt32 {
 
 // ColumnInt64 generated columns type for Int64
 type ColumnInt64 struct {
+	ColumnBase
 	name   string
 	values []int64
 }
@@ -442,6 +447,7 @@ func NewColumnInt64(name string, values []int64) *ColumnInt64 {
 
 // ColumnFloat generated columns type for Float
 type ColumnFloat struct {
+	ColumnBase
 	name   string
 	values []float32
 }
@@ -528,6 +534,7 @@ func NewColumnFloat(name string, values []float32) *ColumnFloat {
 
 // ColumnDouble generated columns type for Double
 type ColumnDouble struct {
+	ColumnBase
 	name   string
 	values []float64
 }
@@ -614,6 +621,7 @@ func NewColumnDouble(name string, values []float64) *ColumnDouble {
 
 // ColumnString generated columns type for String
 type ColumnString struct {
+	ColumnBase
 	name   string
 	values []string
 }
diff --git a/entity/columns_varchar.go b/entity/columns_varchar.go
index c000429..6873f80 100644
--- a/entity/columns_varchar.go
+++ b/entity/columns_varchar.go
@@ -9,6 +9,7 @@ import (
 
 // ColumnVarChar generated columns type for VarChar
 type ColumnVarChar struct {
+	ColumnBase
 	name   string
 	values []string
 }
@@ -36,6 +37,14 @@ func (c *ColumnVarChar) Get(idx int) (interface{}, error) {
 	return c.values[idx], nil
 }
 
+// GetAsString returns value at idx.
+func (c *ColumnVarChar) GetAsString(idx int) (string, error) {
+	if idx < 0 || idx > c.Len() {
+		return "", errors.New("index out of range")
+	}
+	return c.values[idx], nil
+}
+
 // FieldData return column data mapped to schema.FieldData
 func (c *ColumnVarChar) FieldData() *schema.FieldData {
 	fd := &schema.FieldData{
diff --git a/entity/columns_vector_gen.go b/entity/columns_vector_gen.go
index 7d83d17..0a64e36 100755
--- a/entity/columns_vector_gen.go
+++ b/entity/columns_vector_gen.go
@@ -13,6 +13,7 @@ import (
 
 // ColumnBinaryVector generated columns type for BinaryVector
 type ColumnBinaryVector struct {
+	ColumnBase
 	name   string
 	dim    int
 	values [][]byte
@@ -99,6 +100,7 @@ func NewColumnBinaryVector(name string, dim int, values [][]byte) *ColumnBinaryV
 
 // ColumnFloatVector generated columns type for FloatVector
 type ColumnFloatVector struct {
+	ColumnBase
 	name   string
 	dim    int
 	values [][]float32
diff --git a/entity/gen/gen.go b/entity/gen/gen.go
index 70f4803..fdc2d09 100644
--- a/entity/gen/gen.go
+++ b/entity/gen/gen.go
@@ -38,6 +38,7 @@ import (
 {{ range .Types }}{{with .}}
 // Column{{.TypeName}} generated columns type for {{.TypeName}}
 type Column{{.TypeName}} struct {
+	ColumnBase
 	name   string
 	values []{{.TypeDef}}
 }
@@ -138,6 +139,7 @@ import (
 {{ range .Types }}{{with.}}
 // Column{{.TypeName}} generated columns type for {{.TypeName}}
 type Column{{.TypeName}} struct {
+	ColumnBase
 	name   string
 	dim    int
 	values []{{.TypeDef}}
diff --git a/examples/dynamic_schema/dynamic_schema.go b/examples/dynamic_schema/dynamic_schema.go
index 4ea27b7..0d090c7 100644
--- a/examples/dynamic_schema/dynamic_schema.go
+++ b/examples/dynamic_schema/dynamic_schema.go
@@ -17,9 +17,9 @@ const (
 	nEntities, dim = 3000, 128
 	collectionName = "dynamic_example"
 
-	msgFmt                                  = "\n==== %s ====\n"
-	idCol, typeCol, randomCol, embeddingCol = "ID", "type", "random", "embeddings"
-	topK                                    = 3
+	msgFmt                                             = "\n==== %s ====\n"
+	idCol, typeCol, randomCol, sourceCol, embeddingCol = "ID", "type", "random", "source", "embeddings"
+	topK                                               = 4
 )
 
 func main() {
@@ -134,13 +134,13 @@ func main() {
 		})
 	}
 
-	fmt.Printf(msgFmt, "start to insert by rows")
 	_, err = c.InsertByRows(ctx, collectionName, "", rows)
 	if err != nil {
 		log.Fatal("failed to insert by rows: ", err.Error())
 	}
 
 	// insert by map[string]interface{}
+	fmt.Printf(msgFmt, "start to inserting by MapRow")
 	m := make(map[string]interface{})
 	m["ID"] = int64(nEntities)
 	vec := make([]float32, 0, dim)
@@ -186,7 +186,7 @@ func main() {
 	}
 	begin := time.Now()
 	sp, _ := entity.NewIndexIvfFlatSearchParam(16)
-	sRet, err := c.Search(ctx, collectionName, nil, "", []string{ /*randomCol, typeCol*/ "*"}, vec2search,
+	sRet, err := c.Search(ctx, collectionName, nil, "", []string{randomCol, typeCol}, vec2search,
 		embeddingCol, entity.L2, topK, sp)
 	end := time.Now()
 	if err != nil {
@@ -195,7 +195,7 @@ func main() {
 
 	fmt.Println("results:")
 	for _, res := range sRet {
-		printResult(&res)
+		printResult(&res, map[string]string{randomCol: "double", typeCol: "int"})
 	}
 	fmt.Printf("\tsearch latency: %dms\n", end.Sub(begin)/time.Millisecond)
 
@@ -210,7 +210,7 @@ func main() {
 	}
 	fmt.Println("results:")
 	for _, res := range sRet2 {
-		printResult(&res)
+		printResult(&res, map[string]string{randomCol: "double", typeCol: "int"})
 	}
 	fmt.Printf("\tsearch latency: %dms\n", end.Sub(begin)/time.Millisecond)
 
@@ -221,16 +221,16 @@ func main() {
 	if err != nil {
 		log.Fatalf("failed to query result, err: %v", err)
 	}
-	printResultSet(sRet3)
+	printResultSet(sRet3, map[string]string{idCol: "int", randomCol: "double", typeCol: "int"})
 
 	// $meta["source"]
 	expr = "source in [1] and random > 0.1"
 	fmt.Printf(msgFmt, fmt.Sprintf("query with expr `%s`", expr))
-	sRet3, err = c.Query(ctx, collectionName, nil, expr, []string{randomCol, typeCol, "source"}, client.WithLimit(3))
+	sRet3, err = c.Query(ctx, collectionName, nil, expr, []string{randomCol, typeCol, sourceCol}, client.WithLimit(3))
 	if err != nil {
 		log.Fatalf("failed to query result, err: %v", err)
 	}
-	printResultSet(sRet3)
+	printResultSet(sRet3, map[string]string{idCol: "int", randomCol: "double", typeCol: "int", sourceCol: "int"})
 
 	// drop collection
 	fmt.Printf(msgFmt, "drop collection `dynamic_example`")
@@ -239,47 +239,50 @@ func main() {
 	}
 }
 
-func printResultSet(sRets []entity.Column) {
-	for _, field := range sRets {
-		fmt.Println(field.Name(), ":")
-		if dc, ok := field.(*entity.ColumnDynamic); ok {
-			for i := 0; i < field.Len(); i++ {
-				switch dc.Name() {
-				case typeCol, "source":
-					v, err := dc.GetInt64(i)
-					if err != nil {
-						fmt.Println(err.Error())
-						continue
-					}
-					fmt.Print(v)
-				case randomCol:
-					v, err := dc.GetDouble(i)
-					if err != nil {
-						fmt.Println(err.Error())
-						continue
-					}
-					fmt.Print(v)
-				default:
-					continue
+func printResultSet(sRets client.ResultSet, outputInfo map[string]string) {
+	for name, typ := range outputInfo {
+		column := sRets.GetColumn(name)
+		if column == nil {
+			fmt.Printf("column %s not found in result set\n", name)
+			continue
+		}
+
+		fmt.Printf("Result Column %s, count: %d\n", name, column.Len())
+		switch typ {
+		case "int":
+			var data []int64
+			for i := 0; i < column.Len(); i++ {
+				line, err := column.GetAsInt64(i)
+				if err != nil {
+					fmt.Printf("failed to get column %s at index %d, err: %s\n", name, i, err.Error())
 				}
-				if i != field.Len()-1 {
-					fmt.Print(", ")
+				data = append(data, line)
+			}
+			fmt.Println("Data:", data)
+		case "string":
+			var data []string
+			for i := 0; i < column.Len(); i++ {
+				line, err := column.GetAsString(i)
+				if err != nil {
+					fmt.Printf("failed to get column %s at index %d, err: %s\n", name, i, err.Error())
 				}
+				data = append(data, line)
 			}
-			fmt.Println()
-			continue
-		}
-		for i := 0; i < field.Len(); i++ {
-			v, _ := field.Get(i)
-			fmt.Print(v)
-			if i != field.Len()-1 {
-				fmt.Print(", ")
+			fmt.Println("Data:", data)
+		case "double":
+			var data []float64
+			for i := 0; i < column.Len(); i++ {
+				line, err := column.GetAsDouble(i)
+				if err != nil {
+					fmt.Printf("failed to get column %s at index %d, err: %s\n", name, i, err.Error())
+				}
+				data = append(data, line)
 			}
+			fmt.Println("Data:", data)
 		}
-		fmt.Println()
 	}
 }
 
-func printResult(sRet *client.SearchResult) {
-	printResultSet(sRet.Fields)
+func printResult(sRet *client.SearchResult, outputInfo map[string]string) {
+	printResultSet(sRet.Fields, outputInfo)
 }


Test patch:
diff --git a/client/client_mock_test.go b/client/client_mock_test.go
index 0949459..098f18f 100644
--- a/client/client_mock_test.go
+++ b/client/client_mock_test.go
@@ -15,6 +15,7 @@ import (
 	"github.com/stretchr/testify/mock"
 	"github.com/stretchr/testify/suite"
 	"google.golang.org/grpc"
+	"google.golang.org/grpc/credentials/insecure"
 	"google.golang.org/grpc/test/bufconn"
 )
 
@@ -58,8 +59,8 @@ func (s *MockSuiteBase) SetupTest() {
 		Address: "bufnet2",
 		DialOptions: []grpc.DialOption{
 			grpc.WithBlock(),
-			grpc.WithInsecure(),
 			grpc.WithContextDialer(s.mockDialer),
+			grpc.WithTransportCredentials(insecure.NewCredentials()),
 		},
 	})
 	s.Require().NoError(err)
diff --git a/client/data_test.go b/client/data_test.go
index 4c54328..6a4e810 100644
--- a/client/data_test.go
+++ b/client/data_test.go
@@ -365,7 +365,7 @@ func (s *SearchSuite) TestSearchSuccess() {
 		s.Require().NotNil(columnA)
 		column, ok := columnA.(*entity.ColumnDynamic)
 		s.Require().True(ok)
-		v, err := column.GetInt64(0)
+		v, err := column.GetAsInt64(0)
 		s.NoError(err)
 		s.Equal(int64(123), v)
 
@@ -373,7 +373,7 @@ func (s *SearchSuite) TestSearchSuccess() {
 		s.Require().NotNil(columnB)
 		column, ok = columnB.(*entity.ColumnDynamic)
 		s.Require().True(ok)
-		str, err := column.GetString(1)
+		str, err := column.GetAsString(1)
 		s.NoError(err)
 		s.Equal("abc", str)
 	})
@@ -598,7 +598,7 @@ func (s *QuerySuite) TestQuerySuccess() {
 		columnA := rs.GetColumn("A").(*entity.ColumnDynamic)
 		s.Require().True(ok)
 		s.Require().NotNil(columnA)
-		v, err = columnA.GetInt64(0)
+		v, err = columnA.GetAsInt64(0)
 		s.NoError(err)
 		s.Equal(int64(123), v)
 	})
diff --git a/client/rbac_test.go b/client/rbac_test.go
index dc344fb..355f006 100644
--- a/client/rbac_test.go
+++ b/client/rbac_test.go
@@ -3,14 +3,10 @@ package client
 import (
 	"context"
 	"errors"
-	"net"
 	"testing"
 
 	"github.com/milvus-io/milvus-sdk-go/v2/entity"
-	"github.com/milvus-io/milvus-sdk-go/v2/mocks"
 	"github.com/stretchr/testify/suite"
-	"google.golang.org/grpc"
-	"google.golang.org/grpc/test/bufconn"
 
 	tmock "github.com/stretchr/testify/mock"
 
@@ -19,57 +15,7 @@ import (
 )
 
 type RBACSuite struct {
-	suite.Suite
-
-	lis  *bufconn.Listener
-	svr  *grpc.Server
-	mock *mocks.MilvusServiceServer
-
-	client Client
-}
-
-func (s *RBACSuite) SetupSuite() {
-	s.lis = bufconn.Listen(bufSize)
-	s.svr = grpc.NewServer()
-
-	s.mock = &mocks.MilvusServiceServer{}
-
-	server.RegisterMilvusServiceServer(s.svr, s.mock)
-
-	go func() {
-		s.T().Log("start mock server")
-		if err := s.svr.Serve(s.lis); err != nil {
-			s.Fail("failed to server mock server", err.Error())
-		}
-	}()
-}
-
-func (s *RBACSuite) TearDownSuite() {
-	s.svr.Stop()
-	s.lis.Close()
-}
-
-func (s *RBACSuite) mockDialer(context.Context, string) (net.Conn, error) {
-	return s.lis.Dial()
-}
-
-func (s *RBACSuite) SetupTest() {
-	c, err := NewClient(context.Background(), Config{
-		Address: "bufnet2",
-		DialOptions: []grpc.DialOption{
-			grpc.WithBlock(),
-			grpc.WithInsecure(),
-			grpc.WithContextDialer(s.mockDialer),
-		},
-	})
-	s.Require().NoError(err)
-
-	s.client = c
-}
-
-func (s *RBACSuite) TearDownTest() {
-	s.client.Close()
-	s.client = nil
+	MockSuiteBase
 }
 
 func (s *RBACSuite) TestCreateRole() {
diff --git a/client/resource_group_test.go b/client/resource_group_test.go
index bf2ac01..78bc182 100644
--- a/client/resource_group_test.go
+++ b/client/resource_group_test.go
@@ -53,11 +53,6 @@ func (s *ResourceGroupSuite) TestListResourceGroups() {
 	s.Run("request_fails", func() {
 		defer s.resetMock()
 
-		rgs := make([]string, 0, 5)
-		for i := 0; i < 5; i++ {
-			rgs = append(rgs, randStr(10))
-		}
-
 		s.mock.EXPECT().ListResourceGroups(mock.Anything, mock.AnythingOfType("*milvuspb.ListResourceGroupsRequest")).
 			Return(nil, errors.New("mocked grpc error"))
 
@@ -68,11 +63,6 @@ func (s *ResourceGroupSuite) TestListResourceGroups() {
 	s.Run("server_return_err", func() {
 		defer s.resetMock()
 
-		rgs := make([]string, 0, 5)
-		for i := 0; i < 5; i++ {
-			rgs = append(rgs, randStr(10))
-		}
-
 		s.mock.EXPECT().ListResourceGroups(mock.Anything, mock.AnythingOfType("*milvuspb.ListResourceGroupsRequest")).
 			Return(&server.ListResourceGroupsResponse{Status: &common.Status{ErrorCode: common.ErrorCode_UnexpectedError}}, nil)
 
@@ -158,11 +148,6 @@ func (s *ResourceGroupSuite) TestDescribeResourceGroup() {
 			outgoingNum[fmt.Sprintf("coll_%s", randStr(6))] = rand.Int31n(5) + 1
 		}
 
-		type testColl struct {
-			Name      string
-			Capacity  int32
-			Available int32
-		}
 		s.mock.EXPECT().DescribeResourceGroup(mock.Anything, mock.AnythingOfType("*milvuspb.DescribeResourceGroupRequest")).
 			Run(func(_ context.Context, req *server.DescribeResourceGroupRequest) {
 				s.Equal(rgName, req.GetResourceGroup())
@@ -196,10 +181,6 @@ func (s *ResourceGroupSuite) TestDescribeResourceGroup() {
 		defer s.resetMock()
 
 		rgName := randStr(10)
-		rgs := make([]string, 0, 5)
-		for i := 0; i < 5; i++ {
-			rgs = append(rgs, randStr(10))
-		}
 
 		s.mock.EXPECT().DescribeResourceGroup(mock.Anything, mock.AnythingOfType("*milvuspb.DescribeResourceGroupRequest")).
 			Run(func(_ context.Context, req *server.DescribeResourceGroupRequest) {
@@ -215,10 +196,6 @@ func (s *ResourceGroupSuite) TestDescribeResourceGroup() {
 		defer s.resetMock()
 
 		rgName := randStr(10)
-		rgs := make([]string, 0, 5)
-		for i := 0; i < 5; i++ {
-			rgs = append(rgs, randStr(10))
-		}
 
 		s.mock.EXPECT().DescribeResourceGroup(mock.Anything, mock.AnythingOfType("*milvuspb.DescribeResourceGroupRequest")).
 			Run(func(_ context.Context, req *server.DescribeResourceGroupRequest) {
@@ -292,11 +269,6 @@ func (s *ResourceGroupSuite) TestTransferNodes() {
 		targetRg := randStr(10)
 		nodeNum := rand.Int31n(5) + 1
 
-		rgs := make([]string, 0, 5)
-		for i := 0; i < 5; i++ {
-			rgs = append(rgs, randStr(10))
-		}
-
 		s.mock.EXPECT().TransferNode(mock.Anything, mock.AnythingOfType("*milvuspb.TransferNodeRequest")).
 			Run(func(_ context.Context, req *server.TransferNodeRequest) {
 				s.Equal(sourceRg, req.GetSourceResourceGroup())
@@ -360,11 +332,6 @@ func (s *ResourceGroupSuite) TestTransferReplica() {
 		targetRg := randStr(10)
 		replicaNum := rand.Int63n(5) + 1
 
-		rgs := make([]string, 0, 5)
-		for i := 0; i < 5; i++ {
-			rgs = append(rgs, randStr(10))
-		}
-
 		s.mock.EXPECT().TransferReplica(mock.Anything, mock.AnythingOfType("*milvuspb.TransferReplicaRequest")).
 			Run(func(_ context.Context, req *server.TransferReplicaRequest) {
 				s.Equal(sourceRg, req.GetSourceResourceGroup())
diff --git a/entity/columns_dynamic_test.go b/entity/columns_dynamic_test.go
index 017b665..f7a081b 100644
--- a/entity/columns_dynamic_test.go
+++ b/entity/columns_dynamic_test.go
@@ -27,7 +27,7 @@ func (s *ColumnDynamicSuite) TestGetInt() {
 			column := NewColumnDynamic(&ColumnJSONBytes{
 				values: [][]byte{[]byte(c.input)},
 			}, "field")
-			v, err := column.GetInt64(0)
+			v, err := column.GetAsInt64(0)
 			if c.expectErr {
 				s.Error(err)
 				return
@@ -55,7 +55,7 @@ func (s *ColumnDynamicSuite) TestGetString() {
 			column := NewColumnDynamic(&ColumnJSONBytes{
 				values: [][]byte{[]byte(c.input)},
 			}, "field")
-			v, err := column.GetString(0)
+			v, err := column.GetAsString(0)
 			if c.expectErr {
 				s.Error(err)
 				return
@@ -83,7 +83,7 @@ func (s *ColumnDynamicSuite) TestGetBool() {
 			column := NewColumnDynamic(&ColumnJSONBytes{
 				values: [][]byte{[]byte(c.input)},
 			}, "field")
-			v, err := column.GetBool(0)
+			v, err := column.GetAsBool(0)
 			if c.expectErr {
 				s.Error(err)
 				return
@@ -111,7 +111,7 @@ func (s *ColumnDynamicSuite) TestGetDouble() {
 			column := NewColumnDynamic(&ColumnJSONBytes{
 				values: [][]byte{[]byte(c.input)},
 			}, "field")
-			v, err := column.GetDouble(0)
+			v, err := column.GetAsDouble(0)
 			if c.expectErr {
 				s.Error(err)
 				return
@@ -129,16 +129,16 @@ func (s *ColumnDynamicSuite) TestIndexOutOfRange() {
 
 	s.Equal("field", column.Name())
 
-	_, err = column.GetInt64(0)
+	_, err = column.GetAsInt64(0)
 	s.Error(err)
 
-	_, err = column.GetString(0)
+	_, err = column.GetAsString(0)
 	s.Error(err)
 
-	_, err = column.GetBool(0)
+	_, err = column.GetAsBool(0)
 	s.Error(err)
 
-	_, err = column.GetDouble(0)
+	_, err = column.GetAsDouble(0)
 	s.Error(err)
 }