@@ -3,6 +3,7 @@ package replication
3
3
import (
4
4
"fmt"
5
5
"math"
6
+ "strconv"
6
7
7
8
"github.com/go-mysql-org/go-mysql/mysql"
8
9
"github.com/go-mysql-org/go-mysql/utils"
52
53
JsonDiffOperation byte
53
54
)
54
55
56
+ type FloatWithTrailingZero float64
57
+
55
58
const (
56
59
// The JSON value in the given path is replaced with a new value.
57
60
//
@@ -96,6 +99,14 @@ func (jd *JsonDiff) String() string {
96
99
return fmt .Sprintf ("json_diff(op:%s path:%s value:%s)" , jd .Op , jd .Path , jd .Value )
97
100
}
98
101
102
+ func (f FloatWithTrailingZero ) MarshalJSON () ([]byte , error ) {
103
+ if float64 (f ) == float64 (int (f )) {
104
+ return []byte (strconv .FormatFloat (float64 (f ), 'f' , 1 , 64 )), nil
105
+ }
106
+
107
+ return []byte (strconv .FormatFloat (float64 (f ), 'f' , - 1 , 64 )), nil
108
+ }
109
+
99
110
func jsonbGetOffsetSize (isSmall bool ) int {
100
111
if isSmall {
101
112
return jsonbSmallOffsetSize
@@ -124,8 +135,9 @@ func jsonbGetValueEntrySize(isSmall bool) int {
124
135
// the common JSON encoding data.
125
136
func (e * RowsEvent ) decodeJsonBinary (data []byte ) ([]byte , error ) {
126
137
d := jsonBinaryDecoder {
127
- useDecimal : e .useDecimal ,
128
- ignoreDecodeErr : e .ignoreJSONDecodeErr ,
138
+ useDecimal : e .useDecimal ,
139
+ useFloatWithTrailingZero : e .useFloatWithTrailingZero ,
140
+ ignoreDecodeErr : e .ignoreJSONDecodeErr ,
129
141
}
130
142
131
143
if d .isDataShort (data , 1 ) {
@@ -141,9 +153,10 @@ func (e *RowsEvent) decodeJsonBinary(data []byte) ([]byte, error) {
141
153
}
142
154
143
155
type jsonBinaryDecoder struct {
144
- useDecimal bool
145
- ignoreDecodeErr bool
146
- err error
156
+ useDecimal bool
157
+ useFloatWithTrailingZero bool
158
+ ignoreDecodeErr bool
159
+ err error
147
160
}
148
161
149
162
func (d * jsonBinaryDecoder ) decodeValue (tp byte , data []byte ) interface {} {
@@ -175,6 +188,9 @@ func (d *jsonBinaryDecoder) decodeValue(tp byte, data []byte) interface{} {
175
188
case JSONB_UINT64 :
176
189
return d .decodeUint64 (data )
177
190
case JSONB_DOUBLE :
191
+ if d .useFloatWithTrailingZero {
192
+ return d .decodeDoubleWithTrailingZero (data )
193
+ }
178
194
return d .decodeDouble (data )
179
195
case JSONB_STRING :
180
196
return d .decodeString (data )
@@ -395,6 +411,11 @@ func (d *jsonBinaryDecoder) decodeDouble(data []byte) float64 {
395
411
return v
396
412
}
397
413
414
+ func (d * jsonBinaryDecoder ) decodeDoubleWithTrailingZero (data []byte ) FloatWithTrailingZero {
415
+ v := d .decodeDouble (data )
416
+ return FloatWithTrailingZero (v )
417
+ }
418
+
398
419
func (d * jsonBinaryDecoder ) decodeString (data []byte ) string {
399
420
if d .err != nil {
400
421
return ""
0 commit comments