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/06/16 02:18:01 UTC

[GitHub] [shardingsphere] azexcy opened a new pull request, #26380: Fix java.sql.time convert failed when there are negative values

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

   
   
   Changes proposed in this pull request:
     - Fix java.sql.time convert failed when there are negative values
   
   ---
   
   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 #26380: Fix java.sql.time convert failed when there are negative values

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


-- 
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 #26380: Fix java.sql.time convert failed when there are negative values

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


##########
kernel/data-pipeline/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/ColumnValueConvertUtilsTest.java:
##########
@@ -105,4 +107,11 @@ void assertConvertToProtobufMessage() {
         assertThat(((com.google.protobuf.Timestamp) actualMessage).getSeconds(), is(offsetDateTime.toEpochSecond()));
         assertThat(((com.google.protobuf.Timestamp) actualMessage).getNanos(), is(offsetDateTime.getNano()));
     }
+    
+    @Test
+    void assertTimeConvert() {
+        Time time = new Time(-3612 * 1000);
+        Int64Value actualMessage = (Int64Value) ColumnValueConvertUtils.convertToProtobufMessage(time);
+        assertThat(LocalTime.ofNanoOfDay(actualMessage.getValue()), is(time.toLocalTime()));

Review Comment:
   If `time.toLocalTime()` will lose nano time, then it could not verify nano, it's better to verify it in unit test



##########
kernel/data-pipeline/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/ColumnValueConvertUtils.java:
##########
@@ -110,6 +110,9 @@ public static Message convertToProtobufMessage(final Object object) {
             Time time = (Time) object;
             long millis = (int) (time.getTime() % MILLISECONDS_PER_SECOND);
             int nanosOfSecond = (int) (millis * NANOSECONDS_PER_MILLISECOND);
+            if (nanosOfSecond < 0) {
+                nanosOfSecond = (int) (nanosOfSecond + TimeUnit.SECONDS.toNanos(1));
+            }
             LocalTime localTime = LocalTime.of(time.getHours(), time.getMinutes(), time.getSeconds(), nanosOfSecond);

Review Comment:
   Could we simplify negative time conversion without coverting to LocalTime?



-- 
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 #26380: Fix java.sql.time convert failed when there are negative values

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


##########
kernel/data-pipeline/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/ColumnValueConvertUtils.java:
##########
@@ -108,9 +103,7 @@ public static Message convertToProtobufMessage(final Object object) {
         }
         if (object instanceof Time) {
             Time time = (Time) object;
-            long millis = (int) (time.getTime() % MILLISECONDS_PER_SECOND);
-            int nanosOfSecond = (int) (millis * NANOSECONDS_PER_MILLISECOND);
-            LocalTime localTime = LocalTime.of(time.getHours(), time.getMinutes(), time.getSeconds(), nanosOfSecond);
+            LocalTime localTime = LocalTime.of(time.getHours(), time.getMinutes(), time.getSeconds(), new Timestamp(time.getTime()).getNanos());

Review Comment:
   `new Timestamp()` will fix nano is negative value
   <img width="726" alt="image" src="https://github.com/apache/shardingsphere/assets/101622833/bd559fe5-3101-4fa3-bdc4-3deeef49e317">
   



-- 
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 #26380: Fix java.sql.time convert failed when there are negative values

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


##########
kernel/data-pipeline/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/ColumnValueConvertUtilsTest.java:
##########
@@ -105,4 +107,11 @@ void assertConvertToProtobufMessage() {
         assertThat(((com.google.protobuf.Timestamp) actualMessage).getSeconds(), is(offsetDateTime.toEpochSecond()));
         assertThat(((com.google.protobuf.Timestamp) actualMessage).getNanos(), is(offsetDateTime.getNano()));
     }
+    
+    @Test
+    void assertTimeConvert() {
+        Time time = new Time(-3612 * 1000);
+        Int64Value actualMessage = (Int64Value) ColumnValueConvertUtils.convertToProtobufMessage(time);
+        assertThat(LocalTime.ofNanoOfDay(actualMessage.getValue()), is(time.toLocalTime()));

Review Comment:
   Improved



-- 
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