Class MySqlDefaultValueConverter

java.lang.Object
io.debezium.connector.mysql.MySqlDefaultValueConverter
All Implemented Interfaces:
DefaultValueConverter

@Immutable public class MySqlDefaultValueConverter extends Object implements DefaultValueConverter
This class is used by a DDL parser to convert the string default value to a Java type recognized by value converters for a subset of types. The functionality is kept separate from the main converters to centralize the formatting logic if necessary.
Author:
Jiri Pechanec
See Also:
  • AbstractRowsEventDataDeserializer
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • EPOCH_EQUIVALENT_TIMESTAMP

      private static final Pattern EPOCH_EQUIVALENT_TIMESTAMP
    • EPOCH_EQUIVALENT_DATE

      private static final Pattern EPOCH_EQUIVALENT_DATE
    • EPOCH_TIMESTAMP

      private static final String EPOCH_TIMESTAMP
      See Also:
    • EPOCH_DATE

      private static final String EPOCH_DATE
      See Also:
    • TIMESTAMP_PATTERN

      private static final Pattern TIMESTAMP_PATTERN
    • CHARSET_INTRODUCER_PATTERN

      private static final Pattern CHARSET_INTRODUCER_PATTERN
    • TRIM_DATA_TYPES

      @Immutable private static final Set<Integer> TRIM_DATA_TYPES
    • NUMBER_DATA_TYPES

      @Immutable private static final Set<Integer> NUMBER_DATA_TYPES
    • ISO_LOCAL_DATE_WITH_OPTIONAL_TIME

      private static final DateTimeFormatter ISO_LOCAL_DATE_WITH_OPTIONAL_TIME
    • converters

      private final MySqlValueConverters converters
  • Constructor Details

  • Method Details

    • parseDefaultValue

      public Optional<Object> parseDefaultValue(Column column, String defaultValueExpression)
      This interface is used by a DDL parser to convert the string default value to a Java type recognized by value converters for a subset of types.
      Specified by:
      parseDefaultValue in interface DefaultValueConverter
      Parameters:
      column - the column definition describing the data value; never null
      defaultValueExpression - the default value literal; may be null
      Returns:
      value converted to a Java type; optional
    • convert

      public Object convert(Column column, String value)
      Converts a default value from the expected format to a logical object acceptable by the main JDBC converter.
      Parameters:
      column - column definition
      value - string formatted default value
      Returns:
      value converted to a Java type
    • convertToLocalDate

      private Object convertToLocalDate(Column column, String value)
      Converts a string object for an object type of LocalDate or LocalDateTime in case of MySql Date type. If the column definition allows null and default value is 0000-00-00, we need return null; else 0000-00-00 will be replaced with 1970-01-01;
      Parameters:
      column - the column definition describing the data value; never null
      value - the string object to be converted into a LocalDate type or LocalDateTime in case of MySql Date type;
      Returns:
      the converted value;
    • convertToLocalDateTime

      private Object convertToLocalDateTime(Column column, String value)
      Converts a string object for an object type of LocalDateTime. If the column definition allows null and default value is 0000-00-00 00:00:00, we need return null, else 0000-00-00 00:00:00 will be replaced with 1970-01-01 00:00:00;
      Parameters:
      column - the column definition describing the data value; never null
      value - the string object to be converted into a LocalDateTime type;
      Returns:
      the converted value;
    • convertToTimestamp

      private Object convertToTimestamp(Column column, String value)
      Converts a string object for an object type of Timestamp. If the column definition allows null and default value is 0000-00-00 00:00:00, we need return null, else 0000-00-00 00:00:00 will be replaced with 1970-01-01 00:00:00;
      Parameters:
      column - the column definition describing the data value; never null
      value - the string object to be converted into a Timestamp type;
      Returns:
      the converted value;
    • convertToDuration

      private Object convertToDuration(Column column, String value)
      Converts a string object for an object type of Duration.
      Parameters:
      column - the column definition describing the data value; never null
      value - the string object to be converted into a Duration type;
      Returns:
      the converted value;
    • convertToDouble

      private Object convertToDouble(String value)
      Converts a string object for an expected JDBC type of Types.DOUBLE.
      Parameters:
      value - the string object to be converted into a Types.DOUBLE type;
      Returns:
      the converted value;
    • convertToDecimal

      private Object convertToDecimal(Column column, String value)
      Converts a string object for an expected JDBC type of Types.DECIMAL.
      Parameters:
      column - the column definition describing the data value; never null
      value - the string object to be converted into a Types.DECIMAL type;
      Returns:
      the converted value;
    • convertToBits

      private Object convertToBits(Column column, String value)
      Converts a string object for an expected JDBC type of Types.BIT.
      Parameters:
      column - the column definition describing the data value; never null
      value - the string object to be converted into a Types.BIT type;
      Returns:
      the converted value;
    • convertToBit

      private Object convertToBit(String value)
    • convertToBits

      private Object convertToBits(String value)
    • convertToBoolean

      private Object convertToBoolean(String value)
      Converts a string object for an expected JDBC type of Types.BOOLEAN.
      Parameters:
      value - the string object to be converted into a Types.BOOLEAN type;
      Returns:
      the converted value;
    • timestampFormat

      private DateTimeFormatter timestampFormat(int length)
    • cleanTimestamp

      private String cleanTimestamp(String s)
      Clean input timestamp to yyyy-mm-dd hh:mm:ss[.fffffffff] format
      Parameters:
      s - input timestamp
      Returns:
      cleaned timestamp
    • replaceFirstNonNumericSubstring

      private String replaceFirstNonNumericSubstring(String s, int startIndex, char c)
      Replace the first non-numeric substring
      Parameters:
      s - the original string
      startIndex - the beginning index, inclusive
      c - the new character
      Returns:
    • stripCharacterSetIntroducer

      private String stripCharacterSetIntroducer(String value)