@Immutable public class MySqlValueConverters extends JdbcValueConverters
This class always uses UTC for the default time zone when converting values without timezone information to values that require
timezones. This is because MySQL TIMESTAMP values are always
stored in UTC (unlike DATETIME values) and
are replicated in this form. Meanwhile, the MySQL Binlog Client library will deserialize these as Timestamp values that have no timezone and, therefore, are presumed to be in UTC.
When the column is properly marked with a Types.TIMESTAMP_WITH_TIMEZONE type, the converters will need to convert
that Timestamp value into an OffsetDateTime using the default time zone, which always is UTC.
AbstractRowsEventDataDeserializerJdbcValueConverters.BigIntUnsignedMode, JdbcValueConverters.DecimalMode| Modifier and Type | Field and Description |
|---|---|
private static Pattern |
DATE_FIELD_PATTERN
Used to parse values of DATE columns.
|
private static org.slf4j.Logger |
LOGGER |
private static Pattern |
TIME_FIELD_PATTERN
Used to parse values of TIME columns.
|
private static Pattern |
TIMESTAMP_FIELD_PATTERN
Used to parse values of TIMESTAMP columns.
|
adaptiveTimeMicrosecondsPrecisionMode, adaptiveTimePrecisionMode, bigIntUnsignedMode, decimalMode, logger| Constructor and Description |
|---|
MySqlValueConverters(JdbcValueConverters.DecimalMode decimalMode,
TemporalPrecisionMode temporalPrecisionMode,
JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode)
Create a new instance that always uses UTC for the default time zone when converting values without timezone information
to values that require timezones.
|
MySqlValueConverters(JdbcValueConverters.DecimalMode decimalMode,
TemporalPrecisionMode temporalPrecisionMode,
JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode,
TemporalAdjuster adjuster)
Create a new instance that always uses UTC for the default time zone when converting values without timezone information
to values that require timezones.
|
MySqlValueConverters(JdbcValueConverters.DecimalMode decimalMode,
TemporalPrecisionMode temporalPrecisionMode,
ZoneOffset defaultOffset,
JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode,
TemporalAdjuster adjuster)
Create a new instance, and specify the time zone offset that should be used only when converting values without timezone
information to values that require timezones.
|
| Modifier and Type | Method and Description |
|---|---|
protected static Temporal |
adjustTemporal(Temporal temporal)
A utility method that adjusts ambiguous 2-digit
year values of DATETIME, DATE, and TIMESTAMP types using these MySQL-specific rules:
Year values in the range 00-69 are converted to 2000-2069.
Year values in the range 70-99 are converted to 1970-1999.
|
protected ByteOrder |
byteOrderOfBitType() |
protected Charset |
charsetFor(Column column)
Return the
Charset instance with the MySQL-specific character set name used by the given column. |
static boolean |
containsZeroValuesInDatePart(String timestampString,
Column column,
Table table) |
protected ByteBuffer |
convertByteArray(Column column,
byte[] data) |
protected Object |
convertDurationToMicroseconds(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
|
protected Object |
convertEnumToString(List<String> options,
Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Converts a value object for a MySQL
ENUM, which is represented in the binlog events as an integer value containing
the index of the enum option. |
ValueConverter |
converter(Column column,
org.apache.kafka.connect.data.Field fieldDefn) |
protected Object |
convertGeometry(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Convert the a value representing a GEOMETRY
byte[] value to a Geometry value used in a SourceRecord. |
protected Object |
convertJson(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
|
protected Object |
convertPoint(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Convert the a value representing a POINT
byte[] value to a Point value used in a SourceRecord. |
protected Object |
convertSetToString(List<String> options,
Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Converts a value object for a MySQL
SET, which is represented in the binlog events contain a long number in which
every bit corresponds to a different option. |
protected String |
convertSetValue(Column column,
long indexes,
List<String> options) |
protected Object |
convertString(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Charset columnCharset,
Object data)
|
protected Object |
convertTimestampToLocalDateTime(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data) |
protected Object |
convertUnsignedBigint(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Convert the a value representing a Unsigned BIGINT value to the correct Unsigned INT representation.
|
protected Object |
convertUnsignedInt(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Convert the a value representing a Unsigned INT value to the correct Unsigned INT representation.
|
protected Object |
convertUnsignedMediumint(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Convert the a value representing a Unsigned MEDIUMINT value to the correct Unsigned SMALLINT representation.
|
protected Object |
convertUnsignedSmallint(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Convert the a value representing a Unsigned SMALLINT value to the correct Unsigned SMALLINT representation.
|
protected Object |
convertUnsignedTinyint(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Convert the a value representing a Unsigned TINYINT value to the correct Unsigned TINYINT representation.
|
protected Object |
convertYearToInt(Column column,
org.apache.kafka.connect.data.Field fieldDefn,
Object data)
Converts a value object for a MySQL
YEAR, which appear in the binlog as an integer though returns from
the MySQL JDBC driver as either a short or a Date. |
protected List<String> |
extractEnumAndSetOptions(Column column) |
protected String |
extractEnumAndSetOptionsAsString(Column column) |
protected boolean |
isGeometryCollection(String upperCaseTypeName)
Determine if the uppercase form of a column's type is geometry collection independent of JDBC driver or server version.
|
protected boolean |
matches(String upperCaseTypeName,
String upperCaseMatch)
Determine if the uppercase form of a column's type exactly matches or begins with the specified prefix.
|
org.apache.kafka.connect.data.SchemaBuilder |
schemaBuilder(Column column) |
static Duration |
stringToDuration(String timeString) |
static LocalDate |
stringToLocalDate(String dateString,
Column column,
Table table) |
convertBigInt, convertBinary, convertBit, convertBits, convertBits, convertBoolean, convertDateToEpochDays, convertDateToEpochDaysAsDate, convertDecimal, convertDouble, convertFloat, convertInteger, convertNumeric, convertReal, convertRowId, convertSmallInt, convertString, convertTime, convertTimestampToEpochMicros, convertTimestampToEpochMillis, convertTimestampToEpochMillisAsDate, convertTimestampToEpochNanos, convertTimestampWithZone, convertTimeToMicrosPastMidnight, convertTimeToMillisPastMidnight, convertTimeToMillisPastMidnightAsDate, convertTimeToNanosPastMidnight, convertTimeWithZone, convertTinyInt, convertValue, getTimePrecision, handleUnknownData, padLittleEndian, toBigDecimal, unexpectedBinary, withScaleAdjustedIfNeededprivate static final org.slf4j.Logger LOGGER
private static final Pattern TIME_FIELD_PATTERN
private static final Pattern DATE_FIELD_PATTERN
private static final Pattern TIMESTAMP_FIELD_PATTERN
public MySqlValueConverters(JdbcValueConverters.DecimalMode decimalMode, TemporalPrecisionMode temporalPrecisionMode, JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode)
decimalMode - how DECIMAL and NUMERIC values should be treated; may be null if
JdbcValueConverters.DecimalMode.PRECISE is to be usedtemporalPrecisionMode - temporal precision mode based on TemporalPrecisionModebigIntUnsignedMode - how BIGINT UNSIGNED values should be treated; may be null if
JdbcValueConverters.BigIntUnsignedMode.PRECISE is to be usedpublic MySqlValueConverters(JdbcValueConverters.DecimalMode decimalMode, TemporalPrecisionMode temporalPrecisionMode, ZoneOffset defaultOffset, JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode, TemporalAdjuster adjuster)
decimalMode - how DECIMAL and NUMERIC values should be treated; may be null if
JdbcValueConverters.DecimalMode.PRECISE is to be usedtemporalPrecisionMode - temporal precision mode based on TemporalPrecisionModedefaultOffset - the zone offset that is to be used when converting non-timezone related values to values that do
have timezones; may be null if UTC is to be usedbigIntUnsignedMode - how BIGINT UNSIGNED values should be treated; may be null if
JdbcValueConverters.BigIntUnsignedMode.PRECISE is to be usedadjuster - a temporal adjuster to make a database specific time modification before conversionpublic MySqlValueConverters(JdbcValueConverters.DecimalMode decimalMode, TemporalPrecisionMode temporalPrecisionMode, JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode, TemporalAdjuster adjuster)
decimalMode - how DECIMAL and NUMERIC values should be treated; may be null if
JdbcValueConverters.DecimalMode.PRECISE is to be usedtemporalPrecisionMode - temporal precision mode based on TemporalPrecisionModebigIntUnsignedMode - how BIGINT UNSIGNED values should be treated; may be null if
JdbcValueConverters.BigIntUnsignedMode.PRECISE is to be usedadjuster - a temporal adjuster to make a database specific time modification before conversionprotected static Temporal adjustTemporal(Temporal temporal)
temporal - the temporal instance to adjust; may not be nullprotected ByteOrder byteOrderOfBitType()
byteOrderOfBitType in class JdbcValueConverterspublic org.apache.kafka.connect.data.SchemaBuilder schemaBuilder(Column column)
schemaBuilder in interface ValueConverterProviderschemaBuilder in class JdbcValueConverterspublic ValueConverter converter(Column column, org.apache.kafka.connect.data.Field fieldDefn)
converter in interface ValueConverterProviderconverter in class JdbcValueConvertersprotected Charset charsetFor(Column column)
Charset instance with the MySQL-specific character set name used by the given column.column - the column in which the character set is used; never nullCharset, or null if there is no mappingprotected Object convertJson(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertString(Column column, org.apache.kafka.connect.data.Field fieldDefn, Charset columnCharset, Object data)
column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nullcolumnCharset - the Java character set in which column byte[] values are encoded; may not be nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertYearToInt(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
YEAR, which appear in the binlog as an integer though returns from
the MySQL JDBC driver as either a short or a Date.column - the column definition describing the data value; never nullfieldDefn - the field definition; never nulldata - the data object to be converted into a year literal integer value; never nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertEnumToString(List<String> options, Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
ENUM, which is represented in the binlog events as an integer value containing
the index of the enum option. The MySQL JDBC driver returns a string containing the option,
so this method calculates the same.options - the characters that appear in the same order as defined in the column; may not be nullcolumn - the column definition describing the data value; never nullfieldDefn - the field definition; never nulldata - the data object to be converted into an ENUM literal String valueIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertSetToString(List<String> options, Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
SET, which is represented in the binlog events contain a long number in which
every bit corresponds to a different option. The MySQL JDBC driver returns a string containing the comma-separated options,
so this method calculates the same.options - the characters that appear in the same order as defined in the column; may not be nullcolumn - the column definition describing the data value; never nullfieldDefn - the field definition; never nulldata - the data object to be converted into an SET literal String value; never nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected boolean matches(String upperCaseTypeName, String upperCaseMatch)
type contains the type name followed by parentheses.upperCaseTypeName - the upper case form of the column's type nameupperCaseMatch - the upper case form of the expected type or prefix of the type; may not be nulltrue if the type matches the specified type, or false otherwiseprotected boolean isGeometryCollection(String upperCaseTypeName)
upperCaseTypeName - the upper case form of the column's type nametrue if the type is geometry collectionprotected Object convertPoint(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
byte[] value to a Point value used in a SourceRecord.column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertGeometry(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
byte[] value to a Geometry value used in a SourceRecord.column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected ByteBuffer convertByteArray(Column column, byte[] data)
convertByteArray in class JdbcValueConvertersprotected Object convertUnsignedTinyint(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertUnsignedSmallint(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertUnsignedMediumint(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertUnsignedInt(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertUnsignedBigint(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
column - the column in which the value appearsfieldDefn - the field definition for the SourceRecord's Schema; never nulldata - the data; may be nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertDurationToMicroseconds(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
Duration to Long values that represents
the time in microseconds.
Per the JDBC specification, databases should return Time instances, but that's not working
because it can only handle Daytime 00:00:00-23:59:59. We use Duration instead that can handle
the range of -838:59:59.000000 to 838:59:59.000000 of a MySQL TIME type and transfer data as signed INT64 which
reflects the DB value converted to microseconds.
column - the column definition describing the data value; never nullfieldDefn - the field definition; never nulldata - the data object to be converted into a Duration type; never nullIllegalArgumentException - if the value could not be converted but the column does not allow nullsprotected Object convertTimestampToLocalDateTime(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
public static LocalDate stringToLocalDate(String dateString, Column column, Table table)
Copyright © 2019 JBoss by Red Hat. All rights reserved.