Skip to content

Commit

Permalink
diff: fix panic when get empty random value for split chunk (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangXiangUSTC authored May 21, 2020
1 parent 330c1a4 commit 6dd445d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/diff/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ func splitRangeByRandom(db *sql.DB, chunk *ChunkRange, count int, schema string,

for j, column := range columns {
if i == 0 {
if len(randomValues[j]) == 0 {
break
}
newChunk.update(column.Name.O, "", randomValues[j][i], false, true)
} else if i == len(randomValues[0]) {
newChunk.update(column.Name.O, randomValues[j][i-1], "", true, false)
Expand Down
29 changes: 29 additions & 0 deletions pkg/diff/spliter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ func (s *testSpliterSuite) TestSplitRangeByRandom(c *C) {
[]string{"n", "z"},
},
},
}, {
"create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`b`))",
2,
NewChunkRange().copyAndUpdate("b", "a", "z", true, true),
[][]interface{}{
{"g"},
},
[]chunkResult{
{
"((`b` > ?)) AND ((`b` <= ?))",
[]string{"a", "g"},
}, {
"((`b` > ?)) AND ((`b` <= ?))",
[]string{"g", "z"},
},
},
}, {
"create table `test`.`test`(`a` int, `b` varchar(10), `c` float, `d` datetime, primary key(`b`))",
3,
NewChunkRange().copyAndUpdate("b", "a", "z", true, true),
[][]interface{}{
{},
},
[]chunkResult{
{
"((`b` > ?)) AND ((`b` <= ?))",
[]string{"a", "z"},
},
},
},
}

Expand Down

0 comments on commit 6dd445d

Please sign in to comment.