/** * Converts a value object for an expected JDBC type of {@link Types#TIMESTAMP} to {@link java.util.Date} values representing * milliseconds past epoch. * <p> * Per the JDBC specification, databases should return {@link java.sql.Timestamp} instances, which have date and time info * but no time zone info. This method handles {@link java.sql.Date} objects plus any other standard date-related objects such * as {@link java.util.Date}, {@link java.time.LocalTime}, and {@link java.time.LocalDateTime}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return 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 */ protected Object convertTimestampToEpochMillisAsDate(Column column, Field fieldDefn, Object data) { // epoch is the fallback value return convertValue(column, fieldDefn, data, 0L, (r) -> { try { r.deliver(new java.util.Date(Timestamp.toEpochMillis(data, adjuster))); } catch (IllegalArgumentException e) { } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#TIMESTAMP} to {@link Timestamp} values, or milliseconds * past epoch. * <p> * Per the JDBC specification, databases should return {@link java.sql.Timestamp} instances, which have date and time info * but no time zone info. This method handles {@link java.sql.Date} objects plus any other standard date-related objects such * as {@link java.util.Date}, {@link java.time.LocalTime}, and {@link java.time.LocalDateTime}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return 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 */ protected Object convertTimestampToEpochMillis(Column column, Field fieldDefn, Object data) { // epoch is the fallback value return convertValue(column, fieldDefn, data, 0L, (r) -> { try { r.deliver(Timestamp.toEpochMillis(data, adjuster)); } catch (IllegalArgumentException e) { } }); }
assertThat(schemaC.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeC, MySqlValueConverters::adjustTemporal))); assertThat(schemaD.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeD, MySqlValueConverters::adjustTemporal))); assertThat(schemaE.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeE, MySqlValueConverters::adjustTemporal))); java.util.Date date = new java.util.Date(Timestamp.toEpochMillis(localTime, MySqlValueConverters::adjustTemporal)); assertThat(schemaG.defaultValue()).isEqualTo(date);
long toEpochMillis1 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(value2)), MySqlValueConverters::adjustTemporal); assertThat(schemaC.defaultValue()).isEqualTo(toEpochMillis1); long toEpochMillis2 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S").parse(value3)), MySqlValueConverters::adjustTemporal); assertThat(schemaD.defaultValue()).isEqualTo(toEpochMillis2);
long toEpochMillis1 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(value2)), MySqlValueConverters::adjustTemporal); assertThat(schemaC.defaultValue()).isEqualTo(toEpochMillis1); long toEpochMillis2 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S").parse(value3)), MySqlValueConverters::adjustTemporal); assertThat(schemaD.defaultValue()).isEqualTo(toEpochMillis2);
long toEpochMillisE = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(valueE)), MySqlValueConverters::adjustTemporal); assertThat(schemaE.defaultValue()).isEqualTo(toEpochMillisE);
assertThat(c3DateTime.getSecond()).isEqualTo(4); assertThat(c3DateTime.getNano()).isEqualTo((int) TimeUnit.MILLISECONDS.toNanos(780)); assertThat(io.debezium.time.Timestamp.toEpochMillis(c3DateTime, ADJUSTER)).isEqualTo(c3.getTime());
/** * Converts a value object for an expected JDBC type of {@link Types#TIMESTAMP} to {@link java.util.Date} values representing * milliseconds past epoch. * <p> * Per the JDBC specification, databases should return {@link java.sql.Timestamp} instances, which have date and time info * but no time zone info. This method handles {@link java.sql.Date} objects plus any other standard date-related objects such * as {@link java.util.Date}, {@link java.time.LocalTime}, and {@link java.time.LocalDateTime}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return 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 */ protected Object convertTimestampToEpochMillisAsDate(Column column, Field fieldDefn, Object data) { // epoch is the fallback value return convertValue(column, fieldDefn, data, 0L, (r) -> { try { r.deliver(new java.util.Date(Timestamp.toEpochMillis(data, adjuster))); } catch (IllegalArgumentException e) { } }); }
/** * Converts a value object for an expected JDBC type of {@link Types#TIMESTAMP} to {@link Timestamp} values, or milliseconds * past epoch. * <p> * Per the JDBC specification, databases should return {@link java.sql.Timestamp} instances, which have date and time info * but no time zone info. This method handles {@link java.sql.Date} objects plus any other standard date-related objects such * as {@link java.util.Date}, {@link java.time.LocalTime}, and {@link java.time.LocalDateTime}. * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null * @return 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 */ protected Object convertTimestampToEpochMillis(Column column, Field fieldDefn, Object data) { // epoch is the fallback value return convertValue(column, fieldDefn, data, 0L, (r) -> { try { r.deliver(Timestamp.toEpochMillis(data, adjuster)); } catch (IllegalArgumentException e) { } }); }
assertThat(schemaC.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeC, MySqlValueConverters::adjustTemporal))); assertThat(schemaD.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeD, MySqlValueConverters::adjustTemporal))); assertThat(schemaE.defaultValue()).isEqualTo(new java.util.Date(Timestamp.toEpochMillis(localDateTimeE, MySqlValueConverters::adjustTemporal))); java.util.Date date = new java.util.Date(Timestamp.toEpochMillis(localTime, MySqlValueConverters::adjustTemporal)); assertThat(schemaG.defaultValue()).isEqualTo(date);
long toEpochMillis1 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(value2)), MySqlValueConverters::adjustTemporal); assertThat(schemaC.defaultValue()).isEqualTo(toEpochMillis1); long toEpochMillis2 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S").parse(value3)), MySqlValueConverters::adjustTemporal); assertThat(schemaD.defaultValue()).isEqualTo(toEpochMillis2);
long toEpochMillis1 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(value2)), MySqlValueConverters::adjustTemporal); assertThat(schemaC.defaultValue()).isEqualTo(toEpochMillis1); long toEpochMillis2 = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S").parse(value3)), MySqlValueConverters::adjustTemporal); assertThat(schemaD.defaultValue()).isEqualTo(toEpochMillis2);
long toEpochMillisE = Timestamp.toEpochMillis(LocalDateTime.from(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").parse(valueE)), MySqlValueConverters::adjustTemporal); assertThat(schemaE.defaultValue()).isEqualTo(toEpochMillisE);
assertThat(c3DateTime.getSecond()).isEqualTo(4); assertThat(c3DateTime.getNano()).isEqualTo((int) TimeUnit.MILLISECONDS.toNanos(780)); assertThat(io.debezium.time.Timestamp.toEpochMillis(c3DateTime, ADJUSTER)).isEqualTo(c3.getTime());