diff --git a/go/test/endtoend/vreplication/config.go b/go/test/endtoend/vreplication/config.go index 8bb6150c0c5..6d73e4db255 100644 --- a/go/test/endtoend/vreplication/config.go +++ b/go/test/endtoend/vreplication/config.go @@ -3,7 +3,7 @@ package vreplication var ( initialProductSchema = ` create table product(pid int, description varbinary(128), primary key(pid)); -create table customer(cid int, name varbinary(128), typ enum('individual','soho','enterprise'), sport set('football','cricket','baseball'),ts timestamp not null default current_timestamp, primary key(cid)); +create table customer(cid int, name varbinary(128), meta json default null, typ enum('individual','soho','enterprise'), sport set('football','cricket','baseball'),ts timestamp not null default current_timestamp, primary key(cid)) CHARSET=utf8mb4; create table customer_seq(id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence'; create table merchant(mname varchar(128), category varchar(128), primary key(mname)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; create table orders(oid int, cid int, pid int, mname varchar(128), price int, primary key(oid)); diff --git a/go/test/endtoend/vreplication/unsharded_init_data.sql b/go/test/endtoend/vreplication/unsharded_init_data.sql index f8e0cc5d86f..15e2405eb0a 100644 --- a/go/test/endtoend/vreplication/unsharded_init_data.sql +++ b/go/test/endtoend/vreplication/unsharded_init_data.sql @@ -1,5 +1,5 @@ -insert into customer(cid, name, typ, sport) values(1, 'john',1,'football,baseball'); -insert into customer(cid, name, typ, sport) values(2, 'paul','soho','cricket'); +insert into customer(cid, name, typ, sport, meta) values(1, 'john',1,'football,baseball','{}'); +insert into customer(cid, name, typ, sport, meta) values(2, 'paul','soho','cricket',convert(x'7b7d' using utf8mb4)); insert into customer(cid, name, typ, sport) values(3, 'ringo','enterprise',''); insert into merchant(mname, category) values('monoprice', 'electronics'); insert into merchant(mname, category) values('newegg', 'electronics'); diff --git a/go/test/endtoend/vreplication/vreplication_test.go b/go/test/endtoend/vreplication/vreplication_test.go index 899273b9192..dfdb39d7af6 100644 --- a/go/test/endtoend/vreplication/vreplication_test.go +++ b/go/test/endtoend/vreplication/vreplication_test.go @@ -284,6 +284,8 @@ func shardCustomer(t *testing.T, testReverse bool, cells []*Cell, sourceCellOrAl insertQuery2 = "insert into customer(name, cid) values('tempCustomer4', 102)" //ID 102, hence due to reverse_bits in shard -80 require.True(t, validateThatQueryExecutesOnTablet(t, vtgateConn, customerTab1, "customer", insertQuery2, matchInsertQuery2)) + + execVtgateQuery(t, vtgateConn, "customer", "update customer set meta = convert(x'7b7d' using utf8mb4) where cid = 1") reverseKsWorkflow := "product.p2c_reverse" if testReverse { //Reverse Replicate diff --git a/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go b/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go index d02c372469a..c3325c118d7 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go +++ b/go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go @@ -626,7 +626,11 @@ func (tpb *tablePlanBuilder) generateUpdateStatement() *sqlparser.ParsedQuery { switch cexpr.operation { case opExpr: bvf.mode = bvAfter - buf.Myprintf("%v", cexpr.expr) + if cexpr.colType == querypb.Type_JSON { + buf.Myprintf("convert(%v using utf8mb4)", cexpr.expr) + } else { + buf.Myprintf("%v", cexpr.expr) + } case opCount: buf.Myprintf("%v", cexpr.colName) case opSum: diff --git a/go/vt/vttablet/tabletmanager/vreplication/vplayer_flaky_test.go b/go/vt/vttablet/tabletmanager/vreplication/vplayer_flaky_test.go index adf55a3f80f..24e2a1773c9 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/vplayer_flaky_test.go +++ b/go/vt/vttablet/tabletmanager/vreplication/vplayer_flaky_test.go @@ -1270,7 +1270,16 @@ func TestPlayerRowMove(t *testing.T) { func TestPlayerTypes(t *testing.T) { log.Errorf("TestPlayerTypes: flavor is %s", env.Flavor) - + enableJSONColumnTesting := false + flavor := strings.ToLower(env.Flavor) + // Disable tests on percona (which identifies as mysql56) and mariadb platforms in CI since they + // either don't support JSON or JSON support is not enabled by default + if strings.Contains(flavor, "mysql57") || strings.Contains(flavor, "mysql80") { + log.Infof("Running JSON column type tests on flavor %s", flavor) + enableJSONColumnTesting = true + } else { + log.Warningf("Not running JSON column type tests on flavor %s", flavor) + } defer deleteTablet(addTablet(100)) execStatements(t, []string{ @@ -1303,7 +1312,7 @@ func TestPlayerTypes(t *testing.T) { "drop table binary_pk", fmt.Sprintf("drop table %s.binary_pk", vrepldb), }) - if strings.Contains(env.Flavor, "mysql57") { + if enableJSONColumnTesting { execStatements(t, []string{ "create table vitess_json(id int auto_increment, val1 json, val2 json, val3 json, val4 json, val5 json, primary key(id))", fmt.Sprintf("create table %s.vitess_json(id int, val1 json, val2 json, val3 json, val4 json, val5 json, primary key(id))", vrepldb), @@ -1386,8 +1395,7 @@ func TestPlayerTypes(t *testing.T) { {"a\x00\x00\x00", "bbb"}, }, }} - - if strings.Contains(env.Flavor, "mysql57") { + if enableJSONColumnTesting { testcases = append(testcases, testcase{ input: "insert into vitess_json(val1,val2,val3,val4,val5) values (null,'{}','123','{\"a\":[42,100]}', '{\"foo\":\"bar\"}')", output: "insert into vitess_json(id,val1,val2,val3,val4,val5) values (1," + @@ -1398,6 +1406,14 @@ func TestPlayerTypes(t *testing.T) { {"1", "", "{}", "123", `{"a": [42, 100]}`, `{"foo": "bar"}`}, }, }) + testcases = append(testcases, testcase{ + input: "update vitess_json set val4 = '{\"a\": [98, 123]}', val5 = convert(x'7b7d' using utf8mb4)", + output: "update vitess_json set val1=convert(null using utf8mb4), val2=convert('{}' using utf8mb4), val3=convert('123' using utf8mb4), val4=convert('{\\\"a\\\":[98,123]}' using utf8mb4), val5=convert('{}' using utf8mb4) where id=1", + table: "vitess_json", + data: [][]string{ + {"1", "", "{}", "123", `{"a": [98, 123]}`, `{}`}, + }, + }) } for _, tcases := range testcases {