azexcy commented on code in PR #24598:
URL: https://github.com/apache/shardingsphere/pull/24598#discussion_r1136444865
##########
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLFractionalSeconds.java:
##########
@@ -26,41 +27,29 @@
*/
public final class MySQLFractionalSeconds {
- private final int fraction;
+ @Getter
+ private final int nanos;
private final int fractionalSecondsPrecision;
public MySQLFractionalSeconds(final int columnMeta, final
MySQLPacketPayload payload) {
fractionalSecondsPrecision = columnMeta;
- fraction = readFraction(payload);
+ nanos = readFraction(payload);
}
private int readFraction(final MySQLPacketPayload payload) {
Review Comment:
eg. the fractional seconds is `.77` means the precision is 2, equals 0.77
seconds, to nanos is `0.77 * 1000 * 1000 * 1000`, paylod.readInt1() will return
77
the fractional seconds is `.773` means the precision is 3, equals 0.773
seconds, to nanos is `0.773 * 1000 * 1000`, paylod.readUnsignedShort() will
return 773
##########
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLDatetime2BinlogProtocolValue.java:
##########
@@ -46,15 +48,16 @@ private long readDatetimeV2FromPayload(final
MySQLPacketPayload payload) {
private Serializable readDatetime(final MySQLBinlogColumnDef columnDef,
final long datetime, final MySQLPacketPayload payload) {
long datetimeWithoutSign = datetime & (0x8000000000L - 1);
- return readDate(datetimeWithoutSign >> 17) + " " +
readTime(datetimeWithoutSign % (1 << 17)) + new
MySQLFractionalSeconds(columnDef.getColumnMeta(), payload);
- }
-
- private String readDate(final long date) {
+ long date = datetimeWithoutSign >> 17;
long yearAndMonth = date >> 5;
- return String.format("%d-%02d-%02d", yearAndMonth / 13, yearAndMonth %
13, date % (1 << 5));
- }
-
- private String readTime(final long time) {
- return String.format("%02d:%02d:%02d", time >> 12, (time >> 6) % (1 <<
6), time % (1 << 6));
+ int year = (int) (yearAndMonth / 13);
+ int month = (int) (yearAndMonth % 13);
+ int day = (int) (date % (1 << 5));
+ long time = datetimeWithoutSign % (1 << 17);
+ int hour = (int) (time >> 12);
+ int minute = (int) ((time >> 6) % (1 << 6));
+ int second = (int) (time % (1 << 6));
+ MySQLFractionalSeconds fractionalSeconds = new
MySQLFractionalSeconds(columnDef.getColumnMeta(), payload);
+ return Timestamp.valueOf(LocalDateTime.of(year, month, day, hour,
minute, second, fractionalSeconds.getNanos()));
Review Comment:
eg. value is`2023-03-14 19:30:16.770925`
it's the above year, month, day, hour, minute and second, the fractional
seconds is `.770925`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]