From 08ade66c858ae7669458659b8a6976bf1976c82e Mon Sep 17 00:00:00 2001 From: shaoyue Date: Fri, 30 Sep 2022 18:48:55 +0800 Subject: [PATCH] Fix insert varchar, forbid insert string type (#19580) Signed-off-by: shaoyue.chen Signed-off-by: shaoyue.chen --- .../distributed/proxy/httpserver/wrap_request.go | 2 +- .../proxy/httpserver/wrap_request_test.go | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/distributed/proxy/httpserver/wrap_request.go b/internal/distributed/proxy/httpserver/wrap_request.go index 489373eb1b..560c2fccbc 100644 --- a/internal/distributed/proxy/httpserver/wrap_request.go +++ b/internal/distributed/proxy/httpserver/wrap_request.go @@ -89,7 +89,7 @@ func (f FieldData) AsSchemapb() (*schemapb.FieldData, error) { }, }, } - case schemapb.DataType_String: + case schemapb.DataType_VarChar: if len(raw) > 0 { _, ok := raw[0].(string) if !ok { diff --git a/internal/distributed/proxy/httpserver/wrap_request_test.go b/internal/distributed/proxy/httpserver/wrap_request_test.go index b984b88907..ab93a68e04 100644 --- a/internal/distributed/proxy/httpserver/wrap_request_test.go +++ b/internal/distributed/proxy/httpserver/wrap_request_test.go @@ -10,9 +10,9 @@ import ( ) func TestFieldData_AsSchemapb(t *testing.T) { - t.Run("string_ok", func(t *testing.T) { + t.Run("varchar_ok", func(t *testing.T) { fieldData := FieldData{ - Type: schemapb.DataType_String, + Type: schemapb.DataType_VarChar, Field: []interface{}{"a", "b", "c"}, } raw, _ := json.Marshal(fieldData) @@ -20,9 +20,9 @@ func TestFieldData_AsSchemapb(t *testing.T) { _, err := fieldData.AsSchemapb() assert.NoError(t, err) }) - t.Run("string_error", func(t *testing.T) { + t.Run("varchar_error", func(t *testing.T) { fieldData := FieldData{ - Type: schemapb.DataType_String, + Type: schemapb.DataType_VarChar, Field: []interface{}{1, 2, 3}, } raw, _ := json.Marshal(fieldData) @@ -30,7 +30,6 @@ func TestFieldData_AsSchemapb(t *testing.T) { _, err := fieldData.AsSchemapb() assert.Error(t, err) }) - t.Run("bool_ok", func(t *testing.T) { fieldData := FieldData{ Type: schemapb.DataType_Bool, @@ -152,9 +151,9 @@ func TestFieldData_AsSchemapb(t *testing.T) { _, err := fieldData.AsSchemapb() assert.Error(t, err) }) - t.Run("varchar_not_support", func(t *testing.T) { + t.Run("string_not_support", func(t *testing.T) { fieldData := FieldData{ - Type: schemapb.DataType_VarChar, + Type: schemapb.DataType_String, Field: []interface{}{"a", "b", "c"}, } raw, _ := json.Marshal(fieldData)