Class JdbcValueConverters

java.lang.Object
io.debezium.jdbc.JdbcValueConverters
All Implemented Interfaces:
ValueConverterProvider

@Immutable public class JdbcValueConverters extends Object implements ValueConverterProvider
A provider of 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
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
    • defaultOffset

      private final ZoneOffset defaultOffset
    • fallbackTimestampWithTimeZone

      private final String fallbackTimestampWithTimeZone
      Fallback value for TIMESTAMP WITH TZ is epoch
    • fallbackTimeWithTimeZone

      private final String fallbackTimeWithTimeZone
      Fallback value for TIME WITH TZ is 00:00
    • adaptiveTimePrecisionMode

      protected final boolean adaptiveTimePrecisionMode
    • adaptiveTimeMicrosecondsPrecisionMode

      protected final boolean adaptiveTimeMicrosecondsPrecisionMode
    • decimalMode

      protected final JdbcValueConverters.DecimalMode decimalMode
    • adjuster

      private final TemporalAdjuster adjuster
    • bigIntUnsignedMode

      protected final JdbcValueConverters.BigIntUnsignedMode bigIntUnsignedMode
    • binaryMode

      protected final CommonConnectorConfig.BinaryHandlingMode 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 - how DECIMAL and NUMERIC values should be treated; may be null if JdbcValueConverters.DecimalMode.PRECISE is to be used
      temporalPrecisionMode - temporal precision mode based on TemporalPrecisionMode
      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 used
      adjuster - the optional component that adjusts the local date value before obtaining the epoch day; may be null if no adjustment is necessary
      bigIntUnsignedMode - how BIGINT UNSIGNED values should be treated; may be null if JdbcValueConverters.BigIntUnsignedMode.PRECISE is to be used
      binaryMode - how binary columns should be represented
  • Method Details

    • schemaBuilder

      public org.apache.kafka.connect.data.SchemaBuilder schemaBuilder(Column column)
      Description copied from interface: ValueConverterProvider
      Returns a SchemaBuilder for a Schema describing literal values of the given JDBC type.
      Specified by:
      schemaBuilder in interface ValueConverterProvider
      Parameters:
      column - the column definition; never null
      Returns:
      the schema builder; null if the column's type information is unknown
    • converter

      public ValueConverter converter(Column column, org.apache.kafka.connect.data.Field fieldDefn)
      Description copied from interface: ValueConverterProvider
      Returns a ValueConverter that can be used to convert the JDBC values corresponding to the given JDBC temporal type into literal values described by the schema.

      This method is only called when ValueConverterProvider.schemaBuilder(Column) returns a non-null SchemaBuilder for the same column definition.

      Specified by:
      converter in interface ValueConverterProvider
      Parameters:
      column - the column definition; never null
      fieldDefn - the definition for the field in a Kafka Connect Schema describing the output of the function; never null
      Returns:
      the value converter; never null
    • convertBits

      protected ValueConverter convertBits(Column column, org.apache.kafka.connect.data.Field fieldDefn)
    • convertTimestampWithZone

      protected Object convertTimestampWithZone(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
      Converts a value object for an expected JDBC type of Types.TIMESTAMP_WITH_TIMEZONE. The standard ANSI to Java 8 type mappings specify that the preferred mapping (when using JDBC's getObject(...) methods) in Java 8 is to return OffsetDateTime for these values.

      This method handles several types of objects, including OffsetDateTime, Timestamp, Date, LocalTime, and LocalDateTime.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.TIME_WITH_TIMEZONE. The standard ANSI to Java 8 type mappings specify that the preferred mapping (when using JDBC's getObject(...) methods) in Java 8 is to return OffsetTime for these values.

      This method handles several types of objects, including OffsetTime, Time, Date, LocalTime, and LocalDateTime. If any of the types have date components, those date components are ignored.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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

      protected Object convertTime(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
    • convertTimestampToEpochMillis

      protected Object convertTimestampToEpochMillis(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
      Converts a value object for an expected JDBC type of Types.TIMESTAMP to Timestamp 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 handles Date objects plus any other standard date-related objects such as Date, LocalTime, and LocalDateTime.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.TIMESTAMP to MicroTimestamp 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 handles Date objects plus any other standard date-related objects such as Date, LocalTime, and LocalDateTime.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.TIMESTAMP to NanoTimestamp 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 handles Date objects plus any other standard date-related objects such as Date, LocalTime, and LocalDateTime.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.TIMESTAMP to Date 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 handles Date objects plus any other standard date-related objects such as Date, LocalTime, and LocalDateTime.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.TIME to Time 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 handles Date objects plus any other standard date-related objects such as Date, LocalTime, and LocalDateTime. If any of the types might have date components, those date components are ignored.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.TIME to MicroTime 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 handles Date objects plus any other standard date-related objects such as Date, LocalTime, and LocalDateTime. If any of the types might have date components, those date components are ignored.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.TIME to NanoTime 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 handles Date objects plus any other standard date-related objects such as Date, LocalTime, and LocalDateTime. If any of the types might have date components, those date components are ignored.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.TIME to Date 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 handles Date objects plus any other standard date-related objects such as Date, LocalTime, and LocalDateTime. If any of the types might have date components, those date components are ignored.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.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 handles Date objects plus any other standard date-related objects such as Date, LocalDate, and LocalDateTime. If any of the types might have time components, those time components are ignored.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.DATE to the number of days past epoch, but represented as a Date 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 handles Date objects plus any other standard date-related objects such as Date, LocalDate, and LocalDateTime. If any of the types might have time components, those time components are ignored.

      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.BLOB, Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.BLOB, Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.BLOB, Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.BLOB, Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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

      protected ByteBuffer toByteBuffer(Column column, byte[] data)
      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

      protected byte[] normalizeBinaryData(Column column, byte[] data)
      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

      protected byte[] unexpectedBinary(Object value, org.apache.kafka.connect.data.Field fieldDefn)
      Handle the unexpected value from a row with a column type of Types.BLOB, Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY.
      Parameters:
      value - the binary value for which no conversion was found; never null
      fieldDefn - 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 of Types.TINYINT.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.SMALLINT.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.INTEGER.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.INTEGER.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.FLOAT.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.DOUBLE.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.REAL.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.NUMERIC.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.NUMERIC.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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

      protected Object toBigDecimal(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
    • withScaleAdjustedIfNeeded

      protected BigDecimal withScaleAdjustedIfNeeded(Column column, BigDecimal data)
    • convertString

      protected Object convertString(Column column, org.apache.kafka.connect.data.Field fieldDefn, Object data)
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.ROWID.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.BIT.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 of Types.BIT of length 2+.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka Connect date type; never null
      numBytes - 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

      protected ByteOrder byteOrderOfBitType()
      Determine whether the byte[] values for columns of type BIT(n) are big-endian or little-endian. All values for BIT(n) columns are to be returned in little-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 of Types.BOOLEAN.
      Parameters:
      column - the column definition describing the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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 the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka 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

      protected int getTimePrecision(Column column)
    • 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 the data value; never null
      fieldDefn - the field definition; never null
      data - the data object to be converted into a Kafka Connect date type
      fallback - 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 mode
      callback - conversion routine that will be invoked in case the value is not null
      Returns:
      The converted value. Will be null if the inbound value was null and the column is optional. Will be the column's default value (converted to the corresponding KC type, if the inbound value was null, the column is non-optional and has a default value. Will be fallback if the inbound value was null, the column is non-optional and has no default value. Otherwise, it will be the value produced by callback and lastly the result returned by handleUnknownData(Column, Field, Object).
    • supportsLargeTimeValues

      private boolean supportsLargeTimeValues()
    • toByteArray

      private byte[] toByteArray(char[] chars)
    • toByteBuffer

      private ByteBuffer toByteBuffer(char[] chars)
    • toByteBuffer

      private ByteBuffer toByteBuffer(String string)