Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add test case to cover varchar default value #2799

Merged
merged 4 commits into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions tests/multi_source/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"os"
"reflect"
"runtime"
"strconv"
"strings"
"sync"
"time"

"go.uber.org/zap"

"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/ticdc/tests/util"
"go.uber.org/zap"
)

func main() {
Expand Down Expand Up @@ -79,7 +79,7 @@ func runDDLTest(srcs []*sql.DB) {
}()

for i, ddlFunc := range []func(context.Context, *sql.DB){
createDropSchemaDDL, truncateDDL, addDropColumnDDL,
createDropSchemaDDL, truncateDDL, addDropColumnDDL, addDropColumnDDL2,
modifyColumnDDL, addDropIndexDDL,
} {
testName := getFunctionName(ddlFunc)
Expand Down Expand Up @@ -282,6 +282,49 @@ func addDropColumnDDL(ctx context.Context, db *sql.DB) {
}
}

// addDropColumnDDL2 tests the following scenario:
// 1. Create a table, executing DML of this table in background
// 2. alter table add column v1 varchar(20) default "xxx" not null
// 3. Some rows could have no data for column v1, however when we decode them,
// we could use the new table schema (which has the column of v1, caused by
// online DDL). Since the column data doesn't exist, the tidb library will
// fill in a default value, which is a string type. That's why we can get
// either []byte or a string of a column.Value
func addDropColumnDDL2(ctx context.Context, db *sql.DB) {
testName := getFunctionName(addDropColumnDDL2)
mustCreateTable(db, testName)

for value := 1; ; value++ {
select {
case <-ctx.Done():
return
default:
}
sql := fmt.Sprintf("alter table test.`%s` drop column v1", testName)
util.MustExec(db, sql)
time.Sleep(100 * time.Millisecond)

var notNULL string
var defaultValue interface{}

strValue := strconv.Itoa(value)
if value%5 == 0 {
// use default <value>
defaultValue = strValue
} else if value%5 == 1 {
// use default null
defaultValue = nil
} else {
// use default <value> not null
notNULL = "not null"
defaultValue = strValue
}
sql = fmt.Sprintf("alter table test.`%s` add column v1 varchar(20) default ? %s", testName, notNULL)
util.MustExec(db, sql, defaultValue)
time.Sleep(100 * time.Millisecond)
}
}

func modifyColumnDDL(ctx context.Context, db *sql.DB) {
testName := getFunctionName(modifyColumnDDL)
mustCreateTable(db, testName)
Expand Down
27 changes: 26 additions & 1 deletion tests/row_format/data/step3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ create table tp_text
primary key (id)
);

create table tp_text2
(
id int auto_increment,
c_tinytext tinytext null,
c_text text null,
c_mediumtext mediumtext null,
c_longtext longtext null,
c_varchar varchar(16) default "a",
c_char char(16) default "a",
c_tinyblob tinyblob null,
c_blob blob null,
c_mediumblob mediumblob null,
c_longblob longblob null,
c_binary binary(16) default '0xa',
c_varbinary varbinary(16) default '0xa',
constraint pk
primary key (id)
);

create table tp_time
(
id int auto_increment,
Expand Down Expand Up @@ -105,7 +124,13 @@ insert into tp_text(c_tinytext, c_text, c_mediumtext, c_longtext, c_varchar, c_c
c_longblob, c_binary, c_varbinary)
values ('89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0A1A0A',
'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A'
, x'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A');
, x'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A'),
('', '', '', '', '', '', x'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A',
x'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A'),
('89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0A1A0A', x'', x'', x'',
x'', x'', x'');

insert into tp_text2() values();

insert into tp_time()
values ();
Expand Down
2 changes: 2 additions & 0 deletions tests/row_format/data/step4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ values ('89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0A1A0A', '89504E470D0
'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A'
, x'89504E470D0A1A0A', x'89504E470D0A1A0A', x'89504E470D0A1A0A');

insert into tp_text2() values();

insert into tp_time()
values ();

Expand Down