Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public class MysqlDebeziumTimeConverter
private static boolean loggedUnknownTimeClass = false;
private static boolean loggedUnknownTimestampWithTimeZoneClass = false;

private final String[] DATE_TYPES = {"DATE", "DATETIME", "TIME", "TIMESTAMP"};
private final String DATE = "DATE";
private final String DATETIME = "DATETIME";
private final String TIME = "TIME";
private final String TIMESTAMP = "TIMESTAMP";
private final String[] DATE_TYPES = {DATE, DATETIME, TIME, TIMESTAMP};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be static?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you for helping me review the code, I will remove static

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was thinking if DATA_TYPES could be static too, since they're not instance specific.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for reviewing the code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChengJie1053 Seems you didn't address this comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We communicated on DingTalk and felt that removing static would not affect performance.So we decided to keep things the way they are

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's fine to wait @yuxiqian 's comment


protected static final String DATE_FORMAT = "yyyy-MM-dd";
protected static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
Expand Down Expand Up @@ -124,21 +128,21 @@ private void registerDateConverter(
return convertDateDefaultValue(field);
}
switch (columnType.toUpperCase(Locale.ROOT)) {
case "DATE":
case DATE:
if (value instanceof Integer) {
return this.convertToDate(
columnType, LocalDate.ofEpochDay((Integer) value));
}
return this.convertToDate(columnType, value);
case "TIME":
case TIME:
if (value instanceof Long) {
long l =
Math.multiplyExact(
(Long) value, TimeUnit.MICROSECONDS.toNanos(1));
return this.convertToTime(columnType, LocalTime.ofNanoOfDay(l));
}
return this.convertToTime(columnType, value);
case "DATETIME":
case DATETIME:
if (value instanceof Long) {
if (getTimePrecision(field) <= 3) {
return this.convertToTimestamp(
Expand All @@ -152,7 +156,7 @@ private void registerDateConverter(
}
}
return this.convertToTimestamp(columnType, value);
case "TIMESTAMP":
case TIMESTAMP:
return this.convertToTimestampWithTimezone(columnType, value);
default:
throw new IllegalArgumentException(
Expand Down Expand Up @@ -303,13 +307,13 @@ public Object convertDateDefaultValue(RelationalColumn field) {
LocalDateTime.parse(DEFAULT_DATE_FORMAT_PATTERN, originalFormat);
String columnType = field.typeName().toUpperCase();
switch (columnType.toUpperCase(Locale.ROOT)) {
case "DATE":
case DATE:
return dateTime.format(dateFormatter);
case "DATETIME":
case DATETIME:
return dateTime.format(datetimeFormatter);
case "TIME":
case TIME:
return dateTime.format(timeFormatter);
case "TIMESTAMP":
case TIMESTAMP:
return dateTime.format(timestampFormatter);
}
}
Expand Down