@@ -72,6 +72,7 @@ public abstract class AbstractRowsEventDataDeserializer<T extends EventData> imp
72
72
private final Map <Long , TableMapEventData > tableMapEventByTableId ;
73
73
74
74
private boolean deserializeDateAndTimeAsLong ;
75
+ private boolean microsecondsPrecision ;
75
76
private boolean deserializeCharAndBinaryAsByteArray ;
76
77
77
78
public AbstractRowsEventDataDeserializer (Map <Long , TableMapEventData > tableMapEventByTableId ) {
@@ -82,6 +83,10 @@ void setDeserializeDateAndTimeAsLong(boolean value) {
82
83
this .deserializeDateAndTimeAsLong = value ;
83
84
}
84
85
86
+ void setMicrosecondsPrecision (boolean value ) {
87
+ this .microsecondsPrecision = value ;
88
+ }
89
+
85
90
void setDeserializeCharAndBinaryAsByteArray (boolean value ) {
86
91
this .deserializeCharAndBinaryAsByteArray = value ;
87
92
}
@@ -265,13 +270,17 @@ protected Serializable deserializeTimeV2(int meta, ByteArrayInputStream inputStr
265
270
+ fractional-seconds storage (size depends on meta)
266
271
*/
267
272
long time = bigEndianLong (inputStream .read (3 ), 0 , 3 );
273
+ int fsp = deserializeFractionalSeconds (meta , inputStream );
268
274
Long timestamp = asUnixTime (1970 , 1 , 1 ,
269
275
bitSlice (time , 2 , 10 , 24 ),
270
276
bitSlice (time , 12 , 6 , 24 ),
271
277
bitSlice (time , 18 , 6 , 24 ),
272
- deserializeFractionalSeconds ( meta , inputStream )
278
+ fsp / 1000
273
279
);
274
280
if (deserializeDateAndTimeAsLong ) {
281
+ if (microsecondsPrecision ) {
282
+ timestamp = timestamp * 1000 + fsp % 1000 ;
283
+ }
275
284
return timestamp ;
276
285
}
277
286
return timestamp != null ? new java .sql .Time (timestamp ) : null ;
@@ -286,9 +295,12 @@ protected Serializable deserializeTimestamp(ByteArrayInputStream inputStream) th
286
295
}
287
296
288
297
protected Serializable deserializeTimestampV2 (int meta , ByteArrayInputStream inputStream ) throws IOException {
289
- long timestamp = bigEndianLong ( inputStream . read ( 4 ), 0 , 4 ) * 1000 +
290
- deserializeFractionalSeconds ( meta , inputStream ) ;
298
+ int fsp = deserializeFractionalSeconds ( meta , inputStream );
299
+ long timestamp = bigEndianLong ( inputStream . read ( 4 ), 0 , 4 ) * 1000 + fsp / 1000 ;
291
300
if (deserializeDateAndTimeAsLong ) {
301
+ if (microsecondsPrecision ) {
302
+ timestamp = timestamp * 1000 + fsp % 1000 ;
303
+ }
292
304
return timestamp ;
293
305
}
294
306
return new java .sql .Timestamp (timestamp );
@@ -320,16 +332,20 @@ protected Serializable deserializeDatetimeV2(int meta, ByteArrayInputStream inpu
320
332
*/
321
333
long datetime = bigEndianLong (inputStream .read (5 ), 0 , 5 );
322
334
int yearMonth = bitSlice (datetime , 1 , 17 , 40 );
335
+ int fsp = deserializeFractionalSeconds (meta , inputStream );
323
336
Long timestamp = asUnixTime (
324
337
yearMonth / 13 ,
325
338
yearMonth % 13 ,
326
339
bitSlice (datetime , 18 , 5 , 40 ),
327
340
bitSlice (datetime , 23 , 5 , 40 ),
328
341
bitSlice (datetime , 28 , 6 , 40 ),
329
342
bitSlice (datetime , 34 , 6 , 40 ),
330
- deserializeFractionalSeconds ( meta , inputStream )
343
+ fsp / 1000
331
344
);
332
345
if (deserializeDateAndTimeAsLong ) {
346
+ if (microsecondsPrecision ) {
347
+ timestamp = timestamp * 1000 + fsp % 1000 ;
348
+ }
333
349
return timestamp ;
334
350
}
335
351
return timestamp != null ? new java .util .Date (timestamp ) : null ;
@@ -402,8 +418,8 @@ protected Long asUnixTime(int year, int month, int day, int hour, int minute, in
402
418
protected int deserializeFractionalSeconds (int meta , ByteArrayInputStream inputStream ) throws IOException {
403
419
int length = (meta + 1 ) / 2 ;
404
420
if (length > 0 ) {
405
- long fraction = bigEndianLong (inputStream .read (length ), 0 , length );
406
- return ( int ) ( fraction / ( 0.1 * Math .pow (100 , length - 1 )) );
421
+ int fraction = bigEndianInteger (inputStream .read (length ), 0 , length );
422
+ return fraction * ( int ) Math .pow (100 , 3 - length );
407
423
}
408
424
return 0 ;
409
425
}
0 commit comments