class RowDeserializers extends Object
A few of the MySQL Binlog Client row deserializers convert MySQL raw row data into
Date, Time, and Timestamp values using Calendar 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 into LocalDate, LocalTime, LocalDateTime, and
OffsetDateTime.
Unfortunately, all of the methods used to deserialize individual values are defined on the
AbstractRowsEventDataDeserializer base class, and inherited by the DeleteRowsEventDataDeserializer,
UpdateRowsEventDataDeserializer, and WriteRowsEventDataDeserializer 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.
| Modifier and Type | Class and Description |
|---|---|
static class |
RowDeserializers.DeleteRowsDeserializer
A specialization of
DeleteRowsEventDataDeserializer that converts MySQL DATE, TIME,
DATETIME, and TIMESTAMP values to LocalDate, LocalTime, LocalDateTime, and
OffsetDateTime objects, respectively. |
static class |
RowDeserializers.UpdateRowsDeserializer
A specialization of
UpdateRowsEventDataDeserializer that converts MySQL DATE, TIME,
DATETIME, and TIMESTAMP values to LocalDate, LocalTime, LocalDateTime, and
OffsetDateTime objects, respectively. |
static class |
RowDeserializers.WriteRowsDeserializer
A specialization of
WriteRowsEventDataDeserializer that converts MySQL DATE, TIME,
DATETIME, and TIMESTAMP values to LocalDate, LocalTime, LocalDateTime, and
OffsetDateTime objects, respectively. |
| Modifier | Constructor and Description |
|---|---|
private |
RowDeserializers() |
| Modifier and Type | Method and 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 MySQL
DATE value to a LocalDate. |
protected static Serializable |
deserializeDatetime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL
DATETIME value without fractional seconds to a LocalDateTime. |
protected static Serializable |
deserializeDatetimeV2(int meta,
com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL
DATETIME value with fractional seconds to a LocalDateTime. |
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 Serializable |
deserializeString(int length,
com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL string to a
byte[]. |
protected static Serializable |
deserializeTime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL
TIME value without fractional seconds to a LocalTime. |
protected static Serializable |
deserializeTimestamp(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL
TIMESTAMP value without fractional seconds to a OffsetDateTime. |
protected static Serializable |
deserializeTimestampV2(int meta,
com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL
TIMESTAMP value with fractional seconds to a OffsetDateTime. |
protected static Serializable |
deserializeTimeV2(int meta,
com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL
TIME value with fractional seconds to a LocalTime. |
protected static Serializable |
deserializeVarString(int meta,
com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL string to a
byte[]. |
protected static Serializable |
deserializeYear(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
Converts a MySQL
YEAR value to a Year object. |
protected static int[] |
split(long value,
int divider,
int length)
Split the integer into multiple integers.
|
protected static Serializable deserializeString(int length, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
byte[].length - the number of bytes used to store the length of the stringinputStream - the binary stream containing the raw binlog event data for the valuebyte[] objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeVarString(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
byte[].meta - the meta value containing the number of bytes in the length fieldinputStream - the binary stream containing the raw binlog event data for the valuebyte[] objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeDate(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
DATE value to a LocalDate.
This method treats all zero values
for DATE columns as NULL, since they cannot be accurately represented as valid LocalDate objects.
inputStream - the binary stream containing the raw binlog event data for the valueLocalDate objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeTime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
TIME value without fractional seconds to a LocalTime.inputStream - the binary stream containing the raw binlog event data for the valueLocalTime objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeTimeV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
TIME value with fractional seconds to a LocalTime.meta - the meta value containing the fractional second precision, or fspinputStream - the binary stream containing the raw binlog event data for the valueLocalTime objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeDatetime(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
DATETIME value without fractional seconds to a LocalDateTime.
This method treats all zero values
for DATETIME columns as NULL, since they cannot be accurately represented as valid LocalDateTime objects.
inputStream - the binary stream containing the raw binlog event data for the valueLocalDateTime objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeDatetimeV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
DATETIME value with fractional seconds to a LocalDateTime.
This method treats all zero values
for DATETIME columns as NULL, since they cannot be accurately represented as valid LocalDateTime objects.
meta - the meta value containing the fractional second precision, or fspinputStream - the binary stream containing the raw binlog event data for the valueLocalDateTime objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeTimestamp(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
TIMESTAMP value without fractional seconds to a OffsetDateTime.
MySQL stores the TIMESTAMP values as seconds past epoch in UTC, but the resulting OffsetDateTime will
be in the local timezone.inputStream - the binary stream containing the raw binlog event data for the valueOffsetDateTime objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeTimestampV2(int meta, com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
TIMESTAMP value with fractional seconds to a OffsetDateTime.
MySQL stores the TIMESTAMP values as seconds + fractional seconds past epoch in UTC, but the resulting
OffsetDateTime will be in the local timezone.meta - the meta value containing the fractional second precision, or fspinputStream - the binary stream containing the raw binlog event data for the valueOffsetDateTime objectIOException - if there is an error reading from the binlog event dataprotected static Serializable deserializeYear(com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream) throws IOException
YEAR value to a Year object.inputStream - the binary stream containing the raw binlog event data for the valueYear objectIOException - if there is an error reading from the binlog event dataprotected static int[] split(long value,
int divider,
int length)
We can't use/access the private split method in the AbstractRowsEventDataDeserializer class, so we
replicate it here. Note the original is licensed under the same Apache Software License 2.0 as Debezium.
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 arrayprotected static long bigEndianLong(byte[] bytes,
int offset,
int length)
We can't use/access the private bigEndianLong method in the AbstractRowsEventDataDeserializer class, so
we replicate it here. Note the original is licensed under the same Apache Software License 2.0 as Debezium.
bytes - the bytes containing the big-endian representation of the valueoffset - the offset within the bytes byte array where the value startslength - the length of the byte representation within the bytes byte arrayprotected static int bitSlice(long value,
int bitOffset,
int numberOfBits,
int payloadSize)
We can't use/access the private bitSlice method in the AbstractRowsEventDataDeserializer class, so
we replicate it here. Note the original is licensed under the same Apache Software License 2.0 as Debezium.
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 the valueprotected static int deserializeFractionalSecondsInNanos(int fsp,
com.github.shyiko.mysql.binlog.io.ByteArrayInputStream inputStream)
throws IOException
We can't use/access the deserializeFractionalSeconds method in the AbstractRowsEventDataDeserializer 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.
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 streamIOException - if there is an error reading from the binlog event dataCopyright © 2017 JBoss by Red Hat. All rights reserved.