You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "azexcy (via GitHub)" <gi...@apache.org> on 2023/03/14 12:23:16 UTC

[GitHub] [shardingsphere] azexcy opened a new pull request, #24598: Refactor pipeline parse datetime/time of MySQL binlog

azexcy opened a new pull request, #24598:
URL: https://github.com/apache/shardingsphere/pull/24598

   Now, pipeline increment tasks of always return string of MySQL time type, it's different type from inventory tasks.
   
   Changes proposed in this pull request:
     - Refactor pipeline parse datetime/time of MySQL binlog
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz merged pull request #24598: Refactor pipeline parse datetime/time of MySQL binlog

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz merged PR #24598:
URL: https://github.com/apache/shardingsphere/pull/24598


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] azexcy commented on a diff in pull request #24598: Refactor pipeline parse datetime/time of MySQL binlog

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on code in PR #24598:
URL: https://github.com/apache/shardingsphere/pull/24598#discussion_r1136460986


##########
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) {
         switch (fractionalSecondsPrecision) {
             case 1:
             case 2:
-                return payload.readInt1() * 10000;
+                return payload.readInt1() * 10000 * 1000;
             case 3:
             case 4:
-                return payload.getByteBuf().readUnsignedShort() * 100;
+                return payload.getByteBuf().readUnsignedShort() * 100 * 1000;
             case 5:
             case 6:
-                return payload.getByteBuf().readUnsignedMedium();
+                return payload.getByteBuf().readUnsignedMedium() * 1000;
             default:
                 return 0;
         }
     }
-    
-    @Override
-    public String toString() {
-        if (0 == fractionalSecondsPrecision) {
-            return "";
-        }
-        StringBuilder result = new StringBuilder(Integer.toString(fraction));
-        for (int i = result.length(); i < fractionalSecondsPrecision; i++) {
-            result.append("0");
-        }
-        result.setLength(fractionalSecondsPrecision);
-        return "." + result;
-    }

Review Comment:
   There have problem when the fractional seconds just like `025000`
   
   1. `payload.getByteBuf().readUnsignedMedium();` return `25000`
   2. toString will append 0 at end, value = `250000`
   
   so the result is wrong



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] azexcy commented on pull request #24598: Refactor pipeline parse datetime/time of MySQL binlog

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on PR #24598:
URL: https://github.com/apache/shardingsphere/pull/24598#issuecomment-1468066258

   MySQL support store microseconds
   https://dev.mysql.com/doc/refman/8.0/en/fractional-seconds.html
   
   And fractional part that requires from 0 to 3 bytes,
   <img width="695" alt="image" src="https://user-images.githubusercontent.com/101622833/225008869-e6036510-a3fb-4af6-8f64-b9b12e767e54.png">
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24598: Refactor pipeline parse datetime/time of MySQL binlog

Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #24598:
URL: https://github.com/apache/shardingsphere/pull/24598#discussion_r1136481950


##########
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:
   `readFraction` could be `convertFractionalSecondsToNanos`



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] azexcy commented on pull request #24598: Refactor pipeline parse datetime/time of MySQL binlog

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on PR #24598:
URL: https://github.com/apache/shardingsphere/pull/24598#issuecomment-1469191402

   test example :
   1. update t_datetime = '2023-03-15 11:03:37.123457 
   <img width="969" alt="image" src="https://user-images.githubusercontent.com/101622833/225186489-fdb2a6a5-5595-4b9b-9bf5-b93b56a856b8.png">
   
   2. update t_datetime = '2023-03-15 11:03:37.023000'
   <img width="991" alt="image" src="https://user-images.githubusercontent.com/101622833/225186662-fa44a678-7978-46bd-a14d-12122ad9f1bd.png">
   
   3. update t_datetime = '2023-03-15 11:03:37.010000'
   <img width="1075" alt="image" src="https://user-images.githubusercontent.com/101622833/225186812-586c68ca-3f95-4c93-8857-37c58f8ca08f.png">
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] azexcy commented on a diff in pull request #24598: Refactor pipeline parse datetime/time of MySQL binlog

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
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 7730
   
   
   



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] azexcy commented on a diff in pull request #24598: Refactor pipeline parse datetime/time of MySQL binlog

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org