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 deserializers
convert MySQL raw row data intoDate
,Time
, andTimestamp
values usingCalendar
instances (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
AbstractRowsEventDataDeserializer
base class, and inherited by theDeleteRowsEventDataDeserializer
,UpdateRowsEventDataDeserializer
, andWriteRowsEventDataDeserializer
subclasses. 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 class
RowDeserializers.DeleteRowsDeserializer
A specialization ofDeleteRowsEventDataDeserializer
that converts MySQLDATE
,TIME
,DATETIME
, andTIMESTAMP
values toLocalDate
,LocalTime
,LocalDateTime
, andOffsetDateTime
objects, respectively.static class
RowDeserializers.UpdateRowsDeserializer
A specialization ofUpdateRowsEventDataDeserializer
that converts MySQLDATE
,TIME
,DATETIME
, andTIMESTAMP
values toLocalDate
,LocalTime
,LocalDateTime
, andOffsetDateTime
objects, respectively.static class
RowDeserializers.WriteRowsDeserializer
A specialization ofWriteRowsEventDataDeserializer
that converts MySQLDATE
,TIME
,DATETIME
, andTIMESTAMP
values toLocalDate
,LocalTime
,LocalDateTime
, andOffsetDateTime
objects, respectively.
-
Field Summary
Fields Modifier and Type Field Description private static int
MASK_10_BITS
private static int
MASK_6_BITS
-
Constructor Summary
Constructors Modifier Constructor Description private
RowDeserializers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static long
bigEndianLong(byte[] bytes, int offset, int length)
Read a big-endian long value.protected static int
bitSlice(long value, int bitOffset, int numberOfBits, int payloadSize)
Slice an integer out of a portion of long value.protected static Serializable
deserializeDate(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQLDATE
value to aLocalDate
.protected static Serializable
deserializeDatetime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQLDATETIME
value without fractional seconds to aLocalDateTime
.protected static Serializable
deserializeDatetimeV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQLDATETIME
value with fractional seconds to aLocalDateTime
.protected static int
deserializeFractionalSecondsInNanos(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 int
deserializeFractionalSecondsInNanosNegative(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 Serializable
deserializeString(int length, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL string to abyte[]
.protected static Serializable
deserializeTime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQLTIME
value without fractional seconds to aDuration
.protected static Serializable
deserializeTimestamp(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQLTIMESTAMP
value without fractional seconds to aOffsetDateTime
.protected static Serializable
deserializeTimestampV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQLTIMESTAMP
value with fractional seconds to aOffsetDateTime
.protected static Serializable
deserializeTimeV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQLTIME
value with fractional seconds to aDuration
.protected static Serializable
deserializeVarString(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL string to abyte[]
.protected static Serializable
deserializeYear(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQLYEAR
value to aYear
object.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
- themeta
value 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 MySQLDATE
value to aLocalDate
.This method treats all zero values for
DATE
columns as NULL, since they cannot be accurately represented as validLocalDate
objects.- Parameters:
inputStream
- the binary stream containing the raw binlog event data for the value- Returns:
- the
LocalDate
object - 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 MySQLTIME
value without fractional seconds to aDuration
.- Parameters:
inputStream
- the binary stream containing the raw binlog event data for the value- Returns:
- the
LocalTime
object - 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 MySQLTIME
value with fractional seconds to aDuration
.- Parameters:
meta
- themeta
value containing the fractional second precision, orfsp
inputStream
- the binary stream containing the raw binlog event data for the value- Returns:
- the
Duration
object - 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 MySQLDATETIME
value without fractional seconds to aLocalDateTime
.This method treats all zero values for
DATETIME
columns as NULL, since they cannot be accurately represented as validLocalDateTime
objects.- Parameters:
inputStream
- the binary stream containing the raw binlog event data for the value- Returns:
- the
LocalDateTime
object - 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 MySQLDATETIME
value with fractional seconds to aLocalDateTime
.This method treats all zero values for
DATETIME
columns as NULL, since they cannot be accurately represented as validLocalDateTime
objects.- Parameters:
meta
- themeta
value containing the fractional second precision, orfsp
inputStream
- the binary stream containing the raw binlog event data for the value- Returns:
- the
LocalDateTime
object - 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 MySQLTIMESTAMP
value without fractional seconds to aOffsetDateTime
. MySQL stores theTIMESTAMP
values as seconds past epoch in UTC, but the resultingOffsetDateTime
will be in the local timezone.- Parameters:
inputStream
- the binary stream containing the raw binlog event data for the value- Returns:
- the
OffsetDateTime
object - 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 MySQLTIMESTAMP
value with fractional seconds to aOffsetDateTime
. MySQL stores theTIMESTAMP
values as seconds + fractional seconds past epoch in UTC, but the resultingOffsetDateTime
will be in the local timezone.- Parameters:
meta
- themeta
value containing the fractional second precision, orfsp
inputStream
- the binary stream containing the raw binlog event data for the value- Returns:
- the
OffsetDateTime
object - 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 MySQLYEAR
value to aYear
object.- Parameters:
inputStream
- the binary stream containing the raw binlog event data for the value- Returns:
- the
Year
object - 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
split
method in theAbstractRowsEventDataDeserializer
class, 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
bigEndianLong
method in theAbstractRowsEventDataDeserializer
class, 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 thebytes
byte array where the value startslength
- the length of the byte representation within thebytes
byte 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
bitSlice
method in theAbstractRowsEventDataDeserializer
class, 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 IOException
Read the binary input stream to obtain the number of nanoseconds given the fractional seconds precision, or fsp.We can't use/access the
deserializeFractionalSeconds
method in theAbstractRowsEventDataDeserializer
class, 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 IOException
Read the binary input stream to obtain the number of nanoseconds given the fractional seconds precision, or fsp.We can't use/access the
deserializeFractionalSeconds
method in theAbstractRowsEventDataDeserializer
class, 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
-
-