Skip to content

Commit 72a1ce7

Browse files
committed
refactor(canal): Use meaningful name of vars in handleUnsigned func
1 parent 98f9427 commit 72a1ce7

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

canal/rows.go

+11-15
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,24 @@ func (r *RowsEvent) handleUnsigned() {
5252
}
5353

5454
for i := 0; i < len(r.Rows); i++ {
55-
for _, index := range r.Table.UnsignedColumns {
56-
switch t := r.Rows[i][index].(type) {
55+
for _, columnIdx := range r.Table.UnsignedColumns {
56+
switch value := r.Rows[i][columnIdx].(type) {
5757
case int8:
58-
r.Rows[i][index] = uint8(t)
58+
r.Rows[i][columnIdx] = uint8(value)
5959
case int16:
60-
r.Rows[i][index] = uint16(t)
60+
r.Rows[i][columnIdx] = uint16(value)
6161
case int32:
62-
if r.Table.Columns[index].Type == schema.TYPE_MEDIUM_INT {
63-
// problem with mediumint is that it's a 3-byte type. There is no compatible golang type to match that.
64-
// So to convert from negative to positive we'd need to convert the value manually
65-
if t >= 0 {
66-
r.Rows[i][index] = uint32(t)
67-
} else {
68-
r.Rows[i][index] = uint32(maxMediumintUnsigned + t + 1)
69-
}
62+
// problem with mediumint is that it's a 3-byte type. There is no compatible golang type to match that.
63+
// So to convert from negative to positive we'd need to convert the value manually
64+
if value < 0 && r.Table.Columns[columnIdx].Type == schema.TYPE_MEDIUM_INT {
65+
r.Rows[i][columnIdx] = uint32(maxMediumintUnsigned + value + 1)
7066
} else {
71-
r.Rows[i][index] = uint32(t)
67+
r.Rows[i][columnIdx] = uint32(value)
7268
}
7369
case int64:
74-
r.Rows[i][index] = uint64(t)
70+
r.Rows[i][columnIdx] = uint64(value)
7571
case int:
76-
r.Rows[i][index] = uint(t)
72+
r.Rows[i][columnIdx] = uint(value)
7773
default:
7874
// nothing to do
7975
}

0 commit comments

Comments
 (0)