This is an automated email from the ASF dual-hosted git repository.

fanjia pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new a0ef5dac93 [Feature] Support nanosecond in SelectDB DateTimeV2 type 
(#6332)
a0ef5dac93 is described below

commit a0ef5dac93121ade7deecb7f638b6b97fd29edb6
Author: Jia Fan <[email protected]>
AuthorDate: Mon Feb 19 18:07:01 2024 +0800

    [Feature] Support nanosecond in SelectDB DateTimeV2 type (#6332)
---
 .../seatunnel/common/utils/DateTimeUtils.java      |  4 ++
 .../selectdb/serialize/SeaTunnelRowConverter.java  |  3 +-
 .../serialize/SeaTunnelRowConverterTest.java       | 54 ++++++++++++++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)

diff --git 
a/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/DateTimeUtils.java
 
b/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/DateTimeUtils.java
index 885634e8a7..56d21688d8 100644
--- 
a/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/DateTimeUtils.java
+++ 
b/seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/DateTimeUtils.java
@@ -33,6 +33,9 @@ public class DateTimeUtils {
         FORMATTER_MAP.put(
                 Formatter.YYYY_MM_DD_HH_MM_SS,
                 
DateTimeFormatter.ofPattern(Formatter.YYYY_MM_DD_HH_MM_SS.value));
+        FORMATTER_MAP.put(
+                Formatter.YYYY_MM_DD_HH_MM_SS_SSSSSS,
+                
DateTimeFormatter.ofPattern(Formatter.YYYY_MM_DD_HH_MM_SS_SSSSSS.value));
         FORMATTER_MAP.put(
                 Formatter.YYYY_MM_DD_HH_MM_SS_SPOT,
                 
DateTimeFormatter.ofPattern(Formatter.YYYY_MM_DD_HH_MM_SS_SPOT.value));
@@ -71,6 +74,7 @@ public class DateTimeUtils {
 
     public enum Formatter {
         YYYY_MM_DD_HH_MM_SS("yyyy-MM-dd HH:mm:ss"),
+        YYYY_MM_DD_HH_MM_SS_SSSSSS("yyyy-MM-dd HH:mm:ss.SSSSSS"),
         YYYY_MM_DD_HH_MM_SS_SPOT("yyyy.MM.dd HH:mm:ss"),
         YYYY_MM_DD_HH_MM_SS_SLASH("yyyy/MM/dd HH:mm:ss"),
         YYYY_MM_DD_HH_MM_SS_NO_SPLIT("yyyyMMddHHmmss"),
diff --git 
a/seatunnel-connectors-v2/connector-selectdb-cloud/src/main/java/org/apache/seatunnel/connectors/selectdb/serialize/SeaTunnelRowConverter.java
 
b/seatunnel-connectors-v2/connector-selectdb-cloud/src/main/java/org/apache/seatunnel/connectors/selectdb/serialize/SeaTunnelRowConverter.java
index adb3949f2a..4519a73c75 100644
--- 
a/seatunnel-connectors-v2/connector-selectdb-cloud/src/main/java/org/apache/seatunnel/connectors/selectdb/serialize/SeaTunnelRowConverter.java
+++ 
b/seatunnel-connectors-v2/connector-selectdb-cloud/src/main/java/org/apache/seatunnel/connectors/selectdb/serialize/SeaTunnelRowConverter.java
@@ -35,7 +35,8 @@ public class SeaTunnelRowConverter {
     @Builder.Default private DateUtils.Formatter dateFormatter = 
DateUtils.Formatter.YYYY_MM_DD;
 
     @Builder.Default
-    private DateTimeUtils.Formatter dateTimeFormatter = 
DateTimeUtils.Formatter.YYYY_MM_DD_HH_MM_SS;
+    private DateTimeUtils.Formatter dateTimeFormatter =
+            DateTimeUtils.Formatter.YYYY_MM_DD_HH_MM_SS_SSSSSS;
 
     @Builder.Default private TimeUtils.Formatter timeFormatter = 
TimeUtils.Formatter.HH_MM_SS;
 
diff --git 
a/seatunnel-connectors-v2/connector-selectdb-cloud/src/test/java/org/apache/seatunnel/connectors/selectdb/serialize/SeaTunnelRowConverterTest.java
 
b/seatunnel-connectors-v2/connector-selectdb-cloud/src/test/java/org/apache/seatunnel/connectors/selectdb/serialize/SeaTunnelRowConverterTest.java
new file mode 100644
index 0000000000..1c0df39bbd
--- /dev/null
+++ 
b/seatunnel-connectors-v2/connector-selectdb-cloud/src/test/java/org/apache/seatunnel/connectors/selectdb/serialize/SeaTunnelRowConverterTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.selectdb.serialize;
+
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDateTime;
+
+public class SeaTunnelRowConverterTest {
+
+    private static final SeaTunnelRowConverter seaTunnelRowConverter = new 
SeaTunnelRowConverter();
+
+    @Test
+    void testDateTimeWithNano() {
+        Assertions.assertEquals(
+                "2021-01-01 00:00:00.123456",
+                seaTunnelRowConverter.convert(
+                        LocalTimeType.LOCAL_DATE_TIME_TYPE,
+                        LocalDateTime.of(2021, 1, 1, 0, 0, 0, 123456789)));
+        Assertions.assertEquals(
+                "2021-01-01 00:00:00.000000",
+                seaTunnelRowConverter.convert(
+                        LocalTimeType.LOCAL_DATE_TIME_TYPE,
+                        LocalDateTime.of(2021, 1, 1, 0, 0, 0, 0)));
+        Assertions.assertEquals(
+                "2021-01-01 00:00:00.000001",
+                seaTunnelRowConverter.convert(
+                        LocalTimeType.LOCAL_DATE_TIME_TYPE,
+                        LocalDateTime.of(2021, 1, 1, 0, 0, 0, 1000)));
+        Assertions.assertEquals(
+                "2021-01-01 00:00:00.000123",
+                seaTunnelRowConverter.convert(
+                        LocalTimeType.LOCAL_DATE_TIME_TYPE,
+                        LocalDateTime.of(2021, 1, 1, 0, 0, 0, 123456)));
+    }
+}

Reply via email to