Skip to content

Commit

Permalink
[Feature] Support nanosecond in SelectDB DateTimeV2 type (#6332)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hisoka-X authored Feb 19, 2024
1 parent 18d3e86 commit a0ef5da
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -71,6 +74,7 @@ public static String toString(long timestamp, Formatter formatter) {

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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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)));
}
}

0 comments on commit a0ef5da

Please sign in to comment.