Class RowDeserializers
- java.lang.Object
-
- io.debezium.connector.mysql.RowDeserializers
-
public class RowDeserializers extends Object
Custom deserializers for the MySQL Binlog Client library.A few of the
MySQL Binlog Client row deserializersconvert MySQL raw row data intoDate,Time, andTimestampvalues usingCalendarinstances (and thus implicitly use the local timezone to calculate the milliseconds past epoch. Rather than perform this conversion, we prefer to convert the raw MySQL row values directly intoLocalDate,LocalTime,LocalDateTime, andOffsetDateTime.Unfortunately, all of the methods used to deserialize individual values are defined on the
AbstractRowsEventDataDeserializerbase class, and inherited by theDeleteRowsEventDataDeserializer,UpdateRowsEventDataDeserializer, andWriteRowsEventDataDeserializersubclasses. Since we can't provide a new base class, the simplest way to override these methods is to subclass each of these 3 subclasses and override the methods on all 3 classes. It's ugly, but it works.See the MySQL Date Time documentation.
- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRowDeserializers.DeleteRowsDeserializerA specialization ofDeleteRowsEventDataDeserializerthat converts MySQLDATE,TIME,DATETIME, andTIMESTAMPvalues toLocalDate,LocalTime,LocalDateTime, andOffsetDateTimeobjects, respectively.static classRowDeserializers.UpdateRowsDeserializerA specialization ofUpdateRowsEventDataDeserializerthat converts MySQLDATE,TIME,DATETIME, andTIMESTAMPvalues toLocalDate,LocalTime,LocalDateTime, andOffsetDateTimeobjects, respectively.static classRowDeserializers.WriteRowsDeserializerA specialization ofWriteRowsEventDataDeserializerthat converts MySQLDATE,TIME,DATETIME, andTIMESTAMPvalues toLocalDate,LocalTime,LocalDateTime, andOffsetDateTimeobjects, respectively.
-
Field Summary
Fields Modifier and Type Field Description private static intMASK_10_BITSprivate static intMASK_6_BITS
-
Constructor Summary
Constructors Modifier Constructor Description privateRowDeserializers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static longbigEndianLong(byte[] bytes, int offset, int length)Read a big-endian long value.protected static intbitSlice(long value, int bitOffset, int numberOfBits, int payloadSize)Slice an integer out of a portion of long value.protected static SerializabledeserializeDate(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQLDATEvalue to aLocalDate.protected static SerializabledeserializeDatetime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQLDATETIMEvalue without fractional seconds to aLocalDateTime.protected static SerializabledeserializeDatetimeV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQLDATETIMEvalue with fractional seconds to aLocalDateTime.protected static intdeserializeFractionalSecondsInNanos(int fsp, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Read the binary input stream to obtain the number of nanoseconds given the fractional seconds precision, or fsp.protected static intdeserializeFractionalSecondsInNanosNegative(int fsp, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Read the binary input stream to obtain the number of nanoseconds given the fractional seconds precision, or fsp.protected static SerializabledeserializeString(int length, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQL string to abyte[].protected static SerializabledeserializeTime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQLTIMEvalue without fractional seconds to aDuration.protected static SerializabledeserializeTimestamp(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQLTIMESTAMPvalue without fractional seconds to aOffsetDateTime.protected static SerializabledeserializeTimestampV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQLTIMESTAMPvalue with fractional seconds to aOffsetDateTime.protected static SerializabledeserializeTimeV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQLTIMEvalue with fractional seconds to aDuration.protected static SerializabledeserializeVarString(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQL string to abyte[].protected static SerializabledeserializeYear(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)Converts a MySQLYEARvalue to aYearobject.protected static int[]split(long value, int divider, int length)Split the integer into multiple integers.
-
-
-
Field Detail
-
MASK_10_BITS
private static final int MASK_10_BITS
- See Also:
- Constant Field Values
-
MASK_6_BITS
private static final int MASK_6_BITS
- See Also:
- Constant Field Values
-
-
Method Detail
-
deserializeString
protected static Serializable deserializeString(int length, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQL string to abyte[].- Parameters:
length- the number of bytes used to store the length of the stringinputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
byte[]object - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeVarString
protected static Serializable deserializeVarString(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQL string to abyte[].- Parameters:
meta- themetavalue containing the number of bytes in the length fieldinputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
byte[]object - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeDate
protected static Serializable deserializeDate(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQLDATEvalue to aLocalDate.This method treats all zero values for
DATEcolumns as NULL, since they cannot be accurately represented as validLocalDateobjects.- Parameters:
inputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
LocalDateobject - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeTime
protected static Serializable deserializeTime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQLTIMEvalue without fractional seconds to aDuration.- Parameters:
inputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
LocalTimeobject - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeTimeV2
protected static Serializable deserializeTimeV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQLTIMEvalue with fractional seconds to aDuration.- Parameters:
meta- themetavalue containing the fractional second precision, orfspinputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
Durationobject - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeDatetime
protected static Serializable deserializeDatetime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQLDATETIMEvalue without fractional seconds to aLocalDateTime.This method treats all zero values for
DATETIMEcolumns as NULL, since they cannot be accurately represented as validLocalDateTimeobjects.- Parameters:
inputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
LocalDateTimeobject - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeDatetimeV2
protected static Serializable deserializeDatetimeV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQLDATETIMEvalue with fractional seconds to aLocalDateTime.This method treats all zero values for
DATETIMEcolumns as NULL, since they cannot be accurately represented as validLocalDateTimeobjects.- Parameters:
meta- themetavalue containing the fractional second precision, orfspinputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
LocalDateTimeobject - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeTimestamp
protected static Serializable deserializeTimestamp(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQLTIMESTAMPvalue without fractional seconds to aOffsetDateTime. MySQL stores theTIMESTAMPvalues as seconds past epoch in UTC, but the resultingOffsetDateTimewill be in the local timezone.- Parameters:
inputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
OffsetDateTimeobject - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeTimestampV2
protected static Serializable deserializeTimestampV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQLTIMESTAMPvalue with fractional seconds to aOffsetDateTime. MySQL stores theTIMESTAMPvalues as seconds + fractional seconds past epoch in UTC, but the resultingOffsetDateTimewill be in the local timezone.- Parameters:
meta- themetavalue containing the fractional second precision, orfspinputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
OffsetDateTimeobject - Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeYear
protected static Serializable deserializeYear(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
Converts a MySQLYEARvalue to aYearobject.- Parameters:
inputStream- the binary stream containing the raw binlog event data for the value- Returns:
- the
Yearobject - Throws:
IOException- if there is an error reading from the binlog event data
-
split
protected static int[] split(long value, int divider, int length)Split the integer into multiple integers.We can't use/access the private
splitmethod in theAbstractRowsEventDataDeserializerclass, so we replicate it here. Note the original is licensed under the same Apache Software License 2.0 as Debezium.- Parameters:
value- the long valuedivider- the value used to separate the individual values (e.g., 10 to separate each digit into a separate value, 100 to separate each pair of digits into a separate value, 1000 to separate each 3 digits into a separate value, etc.)length- the expected length of the integer array- Returns:
- the integer values
-
bigEndianLong
protected static long bigEndianLong(byte[] bytes, int offset, int length)Read a big-endian long value.We can't use/access the private
bigEndianLongmethod in theAbstractRowsEventDataDeserializerclass, so we replicate it here. Note the original is licensed under the same Apache Software License 2.0 as Debezium.- Parameters:
bytes- the bytes containing the big-endian representation of the valueoffset- the offset within thebytesbyte array where the value startslength- the length of the byte representation within thebytesbyte array- Returns:
- the long value
-
bitSlice
protected static int bitSlice(long value, int bitOffset, int numberOfBits, int payloadSize)Slice an integer out of a portion of long value.We can't use/access the private
bitSlicemethod in theAbstractRowsEventDataDeserializerclass, so we replicate it here. Note the original is licensed under the same Apache Software License 2.0 as Debezium.- Parameters:
value- the long containing the integer encoded within itbitOffset- the number of bits where the integer value startsnumberOfBits- the number of bits in the integer valuepayloadSize- the total number of bits used in thevalue- Returns:
- the integer value
-
deserializeFractionalSecondsInNanos
protected static int deserializeFractionalSecondsInNanos(int fsp, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOExceptionRead the binary input stream to obtain the number of nanoseconds given the fractional seconds precision, or fsp.We can't use/access the
deserializeFractionalSecondsmethod in theAbstractRowsEventDataDeserializerclass, so we replicate it here with modifications to support nanoseconds rather than microseconds. Note the original is licensed under the same Apache Software License 2.0 as Debezium.- Parameters:
fsp- the fractional seconds precision describing the number of digits precision used to store the fractional seconds (e.g., 1 for storing tenths of a second, 2 for storing hundredths, 3 for storing milliseconds, etc.)inputStream- the binary data stream- Returns:
- the number of nanoseconds
- Throws:
IOException- if there is an error reading from the binlog event data
-
deserializeFractionalSecondsInNanosNegative
protected static int deserializeFractionalSecondsInNanosNegative(int fsp, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOExceptionRead the binary input stream to obtain the number of nanoseconds given the fractional seconds precision, or fsp.We can't use/access the
deserializeFractionalSecondsmethod in theAbstractRowsEventDataDeserializerclass, so we replicate it here with modifications to support nanoseconds rather than microseconds and negative values. Note the original is licensed under the same Apache Software License 2.0 as Debezium.- Parameters:
fsp- the fractional seconds precision describing the number of digits precision used to store the fractional seconds (e.g., 1 for storing tenths of a second, 2 for storing hundredths, 3 for storing milliseconds, etc.)inputStream- the binary data stream- Returns:
- the number of nanoseconds
- Throws:
IOException- if there is an error reading from the binlog event data
-
-