Class JdbcValueConverters
- All Implemented Interfaces:
ValueConverterProvider
ValueConverters and SchemaBuilders 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
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final booleanprivate final TemporalAdjusterprotected final JdbcValueConverters.BigIntUnsignedModeprotected final CommonConnectorConfig.BinaryHandlingModeprotected final JdbcValueConverters.DecimalModeprivate final ZoneOffsetprivate final StringFallback value for TIMESTAMP WITH TZ is epochprivate final StringFallback value for TIME WITH TZ is 00:00protected final org.slf4j.Logger -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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 ByteOrderprotected ObjectconvertBigInt(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.INTEGER.protected ObjectconvertBinary(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data, CommonConnectorConfig.BinaryHandlingMode mode) protected ObjectconvertBinaryToBase64(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 ObjectconvertBinaryToBytes(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 ObjectconvertBinaryToHex(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 ObjectconvertBit(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BIT.protected ValueConverterconvertBits(Column column, org.apache.kafka.connect.data.Field fieldDefn) protected ObjectconvertBits(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data, int numBytes) Converts a value object for an expected JDBC type ofTypes.BITof length 2+.protected ObjectconvertBoolean(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.BOOLEAN.protected ObjectconvertDateToEpochDays(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DATEto the number of days past epoch.protected ObjectconvertDateToEpochDaysAsDate(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DATEto the number of days past epoch, but represented as aDatevalue at midnight on the date.protected ObjectconvertDecimal(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.NUMERIC.protected ObjectconvertDouble(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.DOUBLE.Returns aValueConverterthat can be used to convert the JDBC values corresponding to the given JDBC temporal type into literal values described by theschema.protected ObjectconvertFloat(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.FLOAT.protected ObjectconvertInteger(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.INTEGER.protected ObjectconvertNumeric(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.NUMERIC.protected ObjectconvertReal(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.REAL.protected ObjectconvertRowId(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.ROWID.protected ObjectconvertSmallInt(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.SMALLINT.protected ObjectconvertString(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 ObjectconvertTime(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) protected ObjectconvertTimestampToEpochMicros(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMPtoMicroTimestampvalues, or microseconds past epoch.protected ObjectconvertTimestampToEpochMillis(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMPtoTimestampvalues, or milliseconds past epoch.protected ObjectconvertTimestampToEpochMillisAsDate(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMPtoDatevalues representing milliseconds past epoch.protected ObjectconvertTimestampToEpochNanos(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMESTAMPtoNanoTimestampvalues, or nanoseconds past epoch.protected ObjectconvertTimestampWithZone(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 ObjectconvertTimeToMicrosPastMidnight(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMEtoMicroTimevalues, or microseconds past midnight.protected ObjectconvertTimeToMillisPastMidnight(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMEtoTimevalues, or milliseconds past midnight.protected ObjectconvertTimeToMillisPastMidnightAsDate(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMEtoDatevalues representing the milliseconds past midnight on the epoch day.protected ObjectconvertTimeToNanosPastMidnight(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TIMEtoNanoTimevalues, or nanoseconds past midnight.protected ObjectconvertTimeWithZone(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 ObjectconvertTinyInt(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) Converts a value object for an expected JDBC type ofTypes.TINYINT.protected ObjectconvertValue(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 intgetTimePrecision(Column column) protected ObjecthandleUnknownData(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.SchemaBuilderschemaBuilder(Column column) Returns aSchemaBuilderfor aSchemadescribing literal values of the given JDBC type.private booleanprotected ObjecttoBigDecimal(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data) private byte[]toByteArray(char[] chars) private ByteBuffertoByteBuffer(char[] chars) protected ByteBuffertoByteBuffer(Column column, byte[] data) Converts the given byte array value into a byte buffer as preferred by Kafka Connect.private ByteBuffertoByteBuffer(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 BigDecimalwithScaleAdjustedIfNeeded(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- howDECIMALandNUMERICvalues should be treated; may be null ifJdbcValueConverters.DecimalMode.PRECISEis to be usedtemporalPrecisionMode- temporal precision mode based onTemporalPrecisionModedefaultOffset- 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 UNSIGNEDvalues should be treated; may be null ifJdbcValueConverters.BigIntUnsignedMode.PRECISEis to be usedbinaryMode- how binary columns should be represented
-
-
Method Details
-
schemaBuilder
Description copied from interface:ValueConverterProviderReturns aSchemaBuilderfor aSchemadescribing literal values of the given JDBC type.- Specified by:
schemaBuilderin 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:ValueConverterProviderReturns aValueConverterthat 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-nullSchemaBuilderfor the same column definition.- Specified by:
converterin interfaceValueConverterProvider- Parameters:
column- the column definition; never nullfieldDefn- the definition for the field in a Kafka ConnectSchemadescribing 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 returnOffsetDateTimefor these values.This method handles several types of objects, including
OffsetDateTime,Timestamp,Date,LocalTime, andLocalDateTime.- Parameters:
column- the column definition describing thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 returnOffsetTimefor 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.TIMESTAMPtoTimestampvalues, or milliseconds past epoch.Per the JDBC specification, databases should return
Timestampinstances, which have date and time info but no time zone info. This method handlesDateobjects plus any other standard date-related objects such asDate,LocalTime, andLocalDateTime.- Parameters:
column- the column definition describing thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.TIMESTAMPtoMicroTimestampvalues, or microseconds past epoch.Per the JDBC specification, databases should return
Timestampinstances, which have date and time info but no time zone info. This method handlesDateobjects plus any other standard date-related objects such asDate,LocalTime, andLocalDateTime.- Parameters:
column- the column definition describing thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.TIMESTAMPtoNanoTimestampvalues, or nanoseconds past epoch.Per the JDBC specification, databases should return
Timestampinstances, which have date and time info but no time zone info. This method handlesDateobjects plus any other standard date-related objects such asDate,LocalTime, andLocalDateTime.- Parameters:
column- the column definition describing thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.TIMESTAMPtoDatevalues representing milliseconds past epoch.Per the JDBC specification, databases should return
Timestampinstances, which have date and time info but no time zone info. This method handlesDateobjects plus any other standard date-related objects such asDate,LocalTime, andLocalDateTime.- Parameters:
column- the column definition describing thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.TIMEtoTimevalues, or milliseconds past midnight.Per the JDBC specification, databases should return
Timeinstances that have no notion of date or time zones. This method handlesDateobjects 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.TIMEtoMicroTimevalues, or microseconds past midnight.Per the JDBC specification, databases should return
Timeinstances that have no notion of date or time zones. This method handlesDateobjects 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.TIMEtoNanoTimevalues, or nanoseconds past midnight.Per the JDBC specification, databases should return
Timeinstances that have no notion of date or time zones. This method handlesDateobjects 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.TIMEtoDatevalues representing the milliseconds past midnight on the epoch day.Per the JDBC specification, databases should return
Timeinstances that have no notion of date or time zones. This method handlesDateobjects 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.DATEto the number of days past epoch.Per the JDBC specification, databases should return
Dateinstances that have no notion of time or time zones. This method handlesDateobjects 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype- 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.DATEto the number of days past epoch, but represented as aDatevalue at midnight on the date.Per the JDBC specification, databases should return
Dateinstances that have no notion of time or time zones. This method handlesDateobjects 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype- 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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.BITof length 2+.- Parameters:
column- the column definition describing thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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-endianorlittle-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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetype; 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 thedatavalue; never nullfieldDefn- the field definition; never nulldata- the data object to be converted into aKafka Connect datetypefallback- 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
nullif the inbound value wasnulland 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 befallbackif the inbound value wasnull, the column is non-optional and has no default value. Otherwise, it will be the value produced bycallbackand lastly the result returned byhandleUnknownData(Column, Field, Object).
-
supportsLargeTimeValues
private boolean supportsLargeTimeValues() -
toByteArray
private byte[] toByteArray(char[] chars) -
toByteBuffer
-
toByteBuffer
-