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

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #26380: Fix java.sql.time convert failed when there are negative values

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