From 44c925cd392d13723f8fc662462c357d13493cb0 Mon Sep 17 00:00:00 2001 From: daviszhen Date: Wed, 18 Dec 2024 14:35:59 +0800 Subject: [PATCH] update --- pkg/frontend/mysql_protocol_test.go | 78 +++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/pkg/frontend/mysql_protocol_test.go b/pkg/frontend/mysql_protocol_test.go index 49c8e882c9489..ed6f9ad8920f6 100644 --- a/pkg/frontend/mysql_protocol_test.go +++ b/pkg/frontend/mysql_protocol_test.go @@ -40,6 +40,7 @@ import ( "github.com/matrixorigin/matrixone/pkg/common/moerr" "github.com/matrixorigin/matrixone/pkg/config" "github.com/matrixorigin/matrixone/pkg/container/batch" + "github.com/matrixorigin/matrixone/pkg/container/bytejson" "github.com/matrixorigin/matrixone/pkg/container/types" "github.com/matrixorigin/matrixone/pkg/container/vector" "github.com/matrixorigin/matrixone/pkg/defines" @@ -2875,3 +2876,80 @@ func (fp *testMysqlWriter) Flush() error { func (fp *testMysqlWriter) MakeColumnDefData(ctx context.Context, columns []*planPb.ColDef) ([][]byte, error) { return nil, nil } + +func newMrsForBinary() *MysqlResultSet { + mrs := &MysqlResultSet{} + + col1 := &MysqlColumn{} + col1.SetName("a") + col1.SetColumnType(defines.MYSQL_TYPE_VARCHAR) + + col2 := &MysqlColumn{} + col2.SetName("b") + col2.SetColumnType(defines.MYSQL_TYPE_STRING) + + col3 := &MysqlColumn{} + col3.SetName("c") + col3.SetColumnType(defines.MYSQL_TYPE_JSON) + + mrs.AddColumn(col1) + mrs.AddColumn(col2) + mrs.AddColumn(col3) + + c3, _ := bytejson.CreateByteJSON("c1") + + rows := [][]any{ + {"a1", []byte("b1"), c3}, + } + + for _, row := range rows { + mrs.AddRow(row) + } + + return mrs +} + +func Test_appendResultSetBinaryRow(t *testing.T) { + ctx := context.TODO() + convey.Convey("append result set binary row", t, func() { + sv, err := getSystemVariables("test/system_vars_config.toml") + if err != nil { + t.Error(err) + } + pu := config.NewParameterUnit(sv, nil, nil, nil) + pu.SV.SkipCheckUser = true + pu.SV.KillRountinesInterval = 0 + setSessionAlloc("", NewLeakCheckAllocator()) + setPu("", pu) + ioses, err := NewIOSession(&testConn{}, pu, "") + convey.ShouldBeNil(err) + proto := NewMysqlClientProtocol("", 0, ioses, 1024, sv) + + ses := NewSession(ctx, "", proto, nil) + proto.ses = ses + + err = proto.appendResultSetBinaryRow(newMrsForBinary(), 0) + convey.So(err, convey.ShouldBeNil) + }) + + convey.Convey("append result set text row", t, func() { + sv, err := getSystemVariables("test/system_vars_config.toml") + if err != nil { + t.Error(err) + } + pu := config.NewParameterUnit(sv, nil, nil, nil) + pu.SV.SkipCheckUser = true + pu.SV.KillRountinesInterval = 0 + setSessionAlloc("", NewLeakCheckAllocator()) + setPu("", pu) + ioses, err := NewIOSession(&testConn{}, pu, "") + convey.ShouldBeNil(err) + proto := NewMysqlClientProtocol("", 0, ioses, 1024, sv) + + ses := NewSession(ctx, "", proto, nil) + proto.ses = ses + + err = proto.appendResultSetTextRow(newMrsForBinary(), 0) + convey.So(err, convey.ShouldBeNil) + }) +}