Skip to content

Commit

Permalink
Merge pull request #6967 from planetscale/jg_fixdecimal
Browse files Browse the repository at this point in the history
Pad non-fractional part of DECIMAL type
  • Loading branch information
rohit-nayak-ps authored Oct 29, 2020
2 parents b8ca49c + cf843d4 commit 7b3767b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go/mysql/binlog_event_rbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func CellValue(data []byte, pos int, typ byte, metadata uint16, styp querypb.Typ
// now the full digits, 32 bits each, 9 digits
for i := 0; i < intg0; i++ {
val = binary.BigEndian.Uint32(d[pos : pos+4])
fmt.Fprintf(txt, "%9d", val)
fmt.Fprintf(txt, "%09d", val)
pos += 4
}

Expand Down
6 changes: 6 additions & 0 deletions go/mysql/binlog_event_rbr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ func TestCellLengthAndData(t *testing.T) {
data: []byte{0x81, 0x0D, 0xFB, 0x38, 0xD2, 0x00, 0x01},
out: sqltypes.MakeTrusted(querypb.Type_DECIMAL,
[]byte("1234567890.0001")),
}, {
typ: TypeNewDecimal,
metadata: 20<<8 | 2, // DECIMAL(20,2)
data: []byte{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x01, 0x0a},
out: sqltypes.MakeTrusted(querypb.Type_DECIMAL,
[]byte("000000000000000001.10")),
}, {
typ: TypeBlob,
metadata: 1,
Expand Down

0 comments on commit 7b3767b

Please sign in to comment.