Class JdbcValueConverters
- All Implemented Interfaces:
ValueConverterProvider
ValueConverter
s and SchemaBuilder
s for various column types. This implementation is aware
of the most common JDBC types and values. Specializations for specific DBMSes can be addressed in subclasses.
Although it is more likely that values will correspond pretty closely to the expected JDBC types, this class assumes it is
possible for some variation to occur when values originate in libraries that are not JDBC drivers. Specifically, the conversion
logic for JDBC temporal types with timezones (e.g., Types.TIMESTAMP_WITH_TIMEZONE
) do support converting values that
don't have timezones (e.g., Timestamp
) by assuming a default time zone offset for values that don't have
(but are expected to have) timezones. Again, when the values are highly-correlated with the expected SQL/JDBC types, this
default timezone offset will not be needed.
- Author:
- Randall Hauch
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
-
Field Summary
Modifier and TypeFieldDescriptionprotected final boolean
protected final boolean
protected final TemporalAdjuster
protected final JdbcValueConverters.BigIntUnsignedMode
protected final CommonConnectorConfig.BinaryHandlingMode
protected final JdbcValueConverters.DecimalMode
protected final ZoneOffset
protected final String
Fallback value for TIMESTAMP WITH TZ is epochprivate final String
Fallback value for TIME WITH TZ is 00:00protected final org.slf4j.Logger
-
Constructor Summary
ConstructorDescriptionCreate a new instance that always uses UTC for the default time zone when converting values without timezone information to values that require timezones, and uses adapts time and timestamp values based upon the precision of the database columns.JdbcValueConverters
(JdbcValueConverters.DecimalMode decimalMode, TemporalPrecisionMode temporalPrecisionMode, ZoneOffset defaultOffset, TemporalAdjuster adjuster, JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode, CommonConnectorConfig.BinaryHandlingMode binaryMode) 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. -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteOrder
protected Object
convertBigInt
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.INTEGER
.protected Object
convertBinary
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data, CommonConnectorConfig.BinaryHandlingMode mode) protected Object
convertBinaryToBase64
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.protected Object
convertBinaryToBase64UrlSafe
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.protected Object
convertBinaryToBytes
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.protected Object
convertBinaryToHex
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.protected Object
convertBit
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BIT
.protected ValueConverter
convertBits
(Column column, org.apache.kafka.connect.data.Field fieldDefn) protected Object
convertBits
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data, int numBytes) Converts a value object for an expected JDBC type ofTypes.BIT
of length 2+.protected Object
convertBoolean
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BOOLEAN
.protected Object
convertDateToEpochDays
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DATE
to the number of days past epoch.protected Object
convertDateToEpochDaysAsDate
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DATE
to the number of days past epoch, but represented as aDate
value at midnight on the date.protected Object
convertDecimal
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.NUMERIC
.protected Object
convertDouble
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DOUBLE
.Returns aValueConverter
that can be used to convert the JDBC values corresponding to the given JDBC temporal type into literal values described by theschema
.protected Object
convertFloat
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.FLOAT
.protected Object
convertInteger
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.INTEGER
.protected Object
convertNumeric
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.NUMERIC
.protected Object
convertReal
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.REAL
.protected Object
convertRowId
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.ROWID
.protected Object
convertSmallInt
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.SMALLINT
.protected Object
convertString
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.CHAR
,Types.VARCHAR
,Types.LONGVARCHAR
,Types.CLOB
,Types.NCHAR
,Types.NVARCHAR
,Types.LONGNVARCHAR
,Types.NCLOB
,Types.DATALINK
, andTypes.SQLXML
.protected Object
convertTime
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) protected Object
convertTimestampToEpochMicros
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP
toMicroTimestamp
values, or microseconds past epoch.protected Object
convertTimestampToEpochMillis
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP
toTimestamp
values, or milliseconds past epoch.protected Object
convertTimestampToEpochMillisAsDate
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP
toDate
values representing milliseconds past epoch.protected Object
convertTimestampToEpochNanos
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP
toNanoTimestamp
values, or nanoseconds past epoch.protected Object
convertTimestampWithZone
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP_WITH_TIMEZONE
.protected Object
convertTimeToMicrosPastMidnight
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME
toMicroTime
values, or microseconds past midnight.protected Object
convertTimeToMillisPastMidnight
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME
toTime
values, or milliseconds past midnight.protected Object
convertTimeToMillisPastMidnightAsDate
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME
toDate
values representing the milliseconds past midnight on the epoch day.protected Object
convertTimeToNanosPastMidnight
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME
toNanoTime
values, or nanoseconds past midnight.protected Object
convertTimeWithZone
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME_WITH_TIMEZONE
.protected Object
convertTinyInt
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TINYINT
.protected Object
convertValue
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data, Object fallback, ValueConversionCallback callback) Converts the given value for the given column/field.protected int
getTimePrecision
(Column column) protected Object
handleUnknownData
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Convert an unknown data value.protected byte[]
normalizeBinaryData
(Column column, byte[] data) Converts the given byte array value into a normalized byte array.protected byte[]
padLittleEndian
(int numBytes, byte[] data) org.apache.kafka.connect.data.SchemaBuilder
schemaBuilder
(Column column) Returns aSchemaBuilder
for aSchema
describing literal values of the given JDBC type.private boolean
protected Object
toBigDecimal
(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) private byte[]
toByteArray
(char[] chars) private ByteBuffer
toByteBuffer
(char[] chars) protected ByteBuffer
toByteBuffer
(Column column, byte[] data) Converts the given byte array value into a byte buffer as preferred by Kafka Connect.private ByteBuffer
toByteBuffer
(String string) protected byte[]
unexpectedBinary
(Object value, org.apache.kafka.connect.data.Field fieldDefn) Handle the unexpected value from a row with a column type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.protected BigDecimal
withScaleAdjustedIfNeeded
(Column column, BigDecimal data)
-
Field Details
-
logger
protected final org.slf4j.Logger logger -
defaultOffset
-
fallbackTimestampWithTimeZone
Fallback value for TIMESTAMP WITH TZ is epoch -
fallbackTimeWithTimeZone
Fallback value for TIME WITH TZ is 00:00 -
adaptiveTimePrecisionMode
protected final boolean adaptiveTimePrecisionMode -
adaptiveTimeMicrosecondsPrecisionMode
protected final boolean adaptiveTimeMicrosecondsPrecisionMode -
decimalMode
-
adjuster
-
bigIntUnsignedMode
-
binaryMode
-
-
Constructor Details
-
JdbcValueConverters
public JdbcValueConverters()Create a new instance that always uses UTC for the default time zone when converting values without timezone information to values that require timezones, and uses adapts time and timestamp values based upon the precision of the database columns. -
JdbcValueConverters
public JdbcValueConverters(JdbcValueConverters.DecimalMode decimalMode, TemporalPrecisionMode temporalPrecisionMode, ZoneOffset defaultOffset, TemporalAdjuster adjuster, JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode, CommonConnectorConfig.BinaryHandlingMode binaryMode) 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. This default offset should not be needed when values are highly-correlated with the expected SQL/JDBC types.- Parameters:
decimalMode
- howDECIMAL
andNUMERIC
values should be treated; may be null ifJdbcValueConverters.DecimalMode.PRECISE
is to be usedtemporalPrecisionMode
- temporal precision mode based onTemporalPrecisionMode
defaultOffset
- 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 usedadjuster
- the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessarybigIntUnsignedMode
- howBIGINT UNSIGNED
values should be treated; may be null ifJdbcValueConverters.BigIntUnsignedMode.PRECISE
is to be usedbinaryMode
- how binary columns should be represented
-
-
Method Details
-
schemaBuilder
Description copied from interface:ValueConverterProvider
Returns aSchemaBuilder
for aSchema
describing literal values of the given JDBC type.- Specified by:
schemaBuilder
in interfaceValueConverterProvider
- Parameters:
column
- the column definition; never null- Returns:
- the schema builder; null if the column's type information is unknown
-
converter
Description copied from interface:ValueConverterProvider
Returns aValueConverter
that can be used to convert the JDBC values corresponding to the given JDBC temporal type into literal values described by theschema
.This method is only called when
ValueConverterProvider.schemaBuilder(Column)
returns a non-nullSchemaBuilder
for the same column definition.- Specified by:
converter
in interfaceValueConverterProvider
- Parameters:
column
- the column definition; never nullfieldDefn
- the definition for the field in a Kafka ConnectSchema
describing the output of the function; never null- Returns:
- the value converter; never null
-
convertBits
-
convertTimestampWithZone
protected Object convertTimestampWithZone(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP_WITH_TIMEZONE
. The standard ANSI to Java 8 type mappings specify that the preferred mapping (when using JDBC'sgetObject(...)
methods) in Java 8 is to returnOffsetDateTime
for these values.This method handles several types of objects, including
OffsetDateTime
,Timestamp
,Date
,LocalTime
, andLocalDateTime
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTimeWithZone
protected Object convertTimeWithZone(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME_WITH_TIMEZONE
. The standard ANSI to Java 8 type mappings specify that the preferred mapping (when using JDBC'sgetObject(...)
methods) in Java 8 is to returnOffsetTime
for these values.This method handles several types of objects, including
OffsetTime
,Time
,Date
,LocalTime
, andLocalDateTime
. If any of the types have date components, those date components are ignored.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTime
-
convertTimestampToEpochMillis
protected Object convertTimestampToEpochMillis(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP
toTimestamp
values, or milliseconds past epoch.Per the JDBC specification, databases should return
Timestamp
instances, which have date and time info but no time zone info. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalTime
, andLocalDateTime
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTimestampToEpochMicros
protected Object convertTimestampToEpochMicros(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP
toMicroTimestamp
values, or microseconds past epoch.Per the JDBC specification, databases should return
Timestamp
instances, which have date and time info but no time zone info. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalTime
, andLocalDateTime
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTimestampToEpochNanos
protected Object convertTimestampToEpochNanos(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP
toNanoTimestamp
values, or nanoseconds past epoch.Per the JDBC specification, databases should return
Timestamp
instances, which have date and time info but no time zone info. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalTime
, andLocalDateTime
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTimestampToEpochMillisAsDate
protected Object convertTimestampToEpochMillisAsDate(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMP
toDate
values representing milliseconds past epoch.Per the JDBC specification, databases should return
Timestamp
instances, which have date and time info but no time zone info. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalTime
, andLocalDateTime
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTimeToMillisPastMidnight
protected Object convertTimeToMillisPastMidnight(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME
toTime
values, or milliseconds past midnight.Per the JDBC specification, databases should return
Time
instances that have no notion of date or time zones. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalTime
, andLocalDateTime
. If any of the types might have date components, those date components are ignored.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTimeToMicrosPastMidnight
protected Object convertTimeToMicrosPastMidnight(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME
toMicroTime
values, or microseconds past midnight.Per the JDBC specification, databases should return
Time
instances that have no notion of date or time zones. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalTime
, andLocalDateTime
. If any of the types might have date components, those date components are ignored.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTimeToNanosPastMidnight
protected Object convertTimeToNanosPastMidnight(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME
toNanoTime
values, or nanoseconds past midnight.Per the JDBC specification, databases should return
Time
instances that have no notion of date or time zones. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalTime
, andLocalDateTime
. If any of the types might have date components, those date components are ignored.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertTimeToMillisPastMidnightAsDate
protected Object convertTimeToMillisPastMidnightAsDate(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIME
toDate
values representing the milliseconds past midnight on the epoch day.Per the JDBC specification, databases should return
Time
instances that have no notion of date or time zones. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalTime
, andLocalDateTime
. If any of the types might have date components, those date components are ignored.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertDateToEpochDays
protected Object convertDateToEpochDays(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DATE
to the number of days past epoch.Per the JDBC specification, databases should return
Date
instances that have no notion of time or time zones. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalDate
, andLocalDateTime
. If any of the types might have time components, those time components are ignored.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertDateToEpochDaysAsDate
protected Object convertDateToEpochDaysAsDate(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DATE
to the number of days past epoch, but represented as aDate
value at midnight on the date.Per the JDBC specification, databases should return
Date
instances that have no notion of time or time zones. This method handlesDate
objects plus any other standard date-related objects such asDate
,LocalDate
, andLocalDateTime
. If any of the types might have time components, those time components are ignored.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertBinary
protected Object convertBinary(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data, CommonConnectorConfig.BinaryHandlingMode mode) -
convertBinaryToBytes
protected Object convertBinaryToBytes(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertBinaryToBase64
protected Object convertBinaryToBase64(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertBinaryToBase64UrlSafe
protected Object convertBinaryToBase64UrlSafe(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertBinaryToHex
protected Object convertBinaryToHex(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
toByteBuffer
Converts the given byte array value into a byte buffer as preferred by Kafka Connect. Specific connectors can perform value adjustments based on the column definition, e.g. right-pad with 0x00 bytes in case of fixed length BINARY in MySQL. -
normalizeBinaryData
Converts the given byte array value into a normalized byte array. Specific connectors can perform value adjustments based on the column definition, e.g. right-pad with 0x00 bytes in case of fixed length BINARY in MySQL. -
unexpectedBinary
Handle the unexpected value from a row with a column type ofTypes.BLOB
,Types.BINARY
,Types.VARBINARY
,Types.LONGVARBINARY
.- Parameters:
value
- the binary value for which no conversion was found; never nullfieldDefn
- the field definition in the Kafka Connect schema; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls- See Also:
-
convertTinyInt
protected Object convertTinyInt(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TINYINT
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertSmallInt
protected Object convertSmallInt(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.SMALLINT
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertInteger
protected Object convertInteger(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.INTEGER
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertBigInt
protected Object convertBigInt(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.INTEGER
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertFloat
protected Object convertFloat(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.FLOAT
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertDouble
protected Object convertDouble(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DOUBLE
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertReal
protected Object convertReal(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.REAL
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertNumeric
protected Object convertNumeric(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.NUMERIC
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertDecimal
protected Object convertDecimal(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.NUMERIC
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
toBigDecimal
-
withScaleAdjustedIfNeeded
-
convertString
protected Object convertString(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.CHAR
,Types.VARCHAR
,Types.LONGVARCHAR
,Types.CLOB
,Types.NCHAR
,Types.NVARCHAR
,Types.LONGNVARCHAR
,Types.NCLOB
,Types.DATALINK
, andTypes.SQLXML
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertRowId
protected Object convertRowId(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.ROWID
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertBit
protected Object convertBit(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BIT
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
convertBits
protected Object convertBits(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data, int numBytes) Converts a value object for an expected JDBC type ofTypes.BIT
of length 2+.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never nullnumBytes
- the number of bytes that should be included in the resulting byte[]- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
padLittleEndian
protected byte[] padLittleEndian(int numBytes, byte[] data) -
byteOrderOfBitType
Determine whether thebyte[]
values for columns of typeBIT(n)
arebig-endian
orlittle-endian
. All values forBIT(n)
columns are to be returned inlittle-endian
.By default, this method returns
ByteOrder.LITTLE_ENDIAN
.- Returns:
- little endian or big endian; never null
-
convertBoolean
protected Object convertBoolean(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BOOLEAN
.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
handleUnknownData
protected Object handleUnknownData(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Convert an unknown data value.- Parameters:
column
- the column definition describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
type; never null- Returns:
- the converted value, or null if the conversion could not be made and the column allows nulls
- Throws:
IllegalArgumentException
- if the value could not be converted but the column does not allow nulls
-
getTimePrecision
-
convertValue
protected Object convertValue(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data, Object fallback, ValueConversionCallback callback) Converts the given value for the given column/field.- Parameters:
column
- describing thedata
value; never nullfieldDefn
- the field definition; never nulldata
- the data object to be converted into aKafka Connect date
typefallback
- value that will be applied in case the column is defined as NOT NULL without a default value, but we still received no value; may happen e.g. when enabling MySQL's non-strict modecallback
- conversion routine that will be invoked in case the value is not null- Returns:
- The converted value. Will be
null
if the inbound value wasnull
and the column is optional. Will be the column's default value (converted to the corresponding KC type, if the inbound value wasnull
, the column is non-optional and has a default value. Will befallback
if the inbound value wasnull
, the column is non-optional and has no default value. Otherwise, it will be the value produced bycallback
and lastly the result returned byhandleUnknownData(Column, Field, Object)
.
-
supportsLargeTimeValues
private boolean supportsLargeTimeValues() -
toByteArray
private byte[] toByteArray(char[] chars) -
toByteBuffer
-
toByteBuffer
-