dybyte commented on code in PR #10360:
URL: https://github.com/apache/seatunnel/pull/10360#discussion_r2707044584
##########
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/functions/DateTimeFunctionsTest.java:
##########
@@ -326,4 +326,143 @@ public void testDateAddWithUnsupportedField() {
rowType,
LocalDate.of(2024, 6, 15)));
}
+
+ @Test
+ public void testParseDateTimeWithAllDateTimeFormats() {
+ SeaTunnelRowType rowType =
+ new SeaTunnelRowType(
+ new String[] {"dummy"},
+ new SeaTunnelDataType[]
{LocalTimeType.LOCAL_DATE_TIME_TYPE});
+
+ // DATETIME_STANDARD: yyyy-MM-dd HH:mm:ss
+ SeaTunnelRow row1 =
+ runSql(
+ "select PARSEDATETIME('2024-06-15 14:30:45',
'yyyy-MM-dd HH:mm:ss') as dt from dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(LocalDateTime.of(2024, 6, 15, 14, 30, 45),
row1.getField(0));
+
+ // DATETIME_WITH_MILLIS: yyyy-MM-dd HH:mm:ss.SSS
+ SeaTunnelRow row2 =
+ runSql(
+ "select PARSEDATETIME('2024-06-15 14:30:45.123',
'yyyy-MM-dd HH:mm:ss.SSS') as dt from dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(
+ LocalDateTime.of(2024, 6, 15, 14, 30, 45, 123000000),
row2.getField(0));
+
+ // DATETIME_ISO8601: yyyy-MM-dd'T'HH:mm:ss
+ SeaTunnelRow row3 =
+ runSql(
+ "select PARSEDATETIME('2024-06-15T14:30:45',
'yyyy-MM-dd''T''HH:mm:ss') as dt from dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(LocalDateTime.of(2024, 6, 15, 14, 30, 45),
row3.getField(0));
+
+ // DATETIME_ISO8601_WITH_MILLIS: yyyy-MM-dd'T'HH:mm:ss.SSS
+ SeaTunnelRow row4 =
+ runSql(
+ "select PARSEDATETIME('2024-06-15T14:30:45.987',
'yyyy-MM-dd''T''HH:mm:ss.SSS') as dt from dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(
+ LocalDateTime.of(2024, 6, 15, 14, 30, 45, 987000000),
row4.getField(0));
+ }
+
+ @Test
+ public void testParseDateTimeWithAllDateFormats() {
+ SeaTunnelRowType rowType =
+ new SeaTunnelRowType(
+ new String[] {"dummy"},
+ new SeaTunnelDataType[]
{LocalTimeType.LOCAL_DATE_TIME_TYPE});
+
+ // DATE_ISO8601: yyyy-MM-dd
+ SeaTunnelRow row1 =
+ runSql(
+ "select PARSEDATETIME('2024-06-15', 'yyyy-MM-dd') as
dt from dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(LocalDate.of(2024, 6, 15), row1.getField(0));
+ }
+
+ @Test
+ public void testParseDateTimeWithAllTimeFormats() {
+ SeaTunnelRowType rowType =
+ new SeaTunnelRowType(
+ new String[] {"dummy"},
+ new SeaTunnelDataType[]
{LocalTimeType.LOCAL_DATE_TIME_TYPE});
+
+ // TIME_STANDARD: HH:mm:ss
+ SeaTunnelRow row1 =
+ runSql(
+ "select PARSEDATETIME('14:30:45', 'HH:mm:ss') as dt
from dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(java.time.LocalTime.of(14, 30, 45),
row1.getField(0));
+
+ // TIME_WITH_MILLIS: HH:mm:ss.SSS
+ SeaTunnelRow row2 =
+ runSql(
+ "select PARSEDATETIME('14:30:45.123', 'HH:mm:ss.SSS')
as dt from dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(java.time.LocalTime.of(14, 30, 45, 123000000),
row2.getField(0));
+ }
+
+ @Test
+ public void testParseDateTimeWithUnsupportedFormat() {
+ SeaTunnelRowType rowType =
+ new SeaTunnelRowType(
+ new String[] {"dummy"},
+ new SeaTunnelDataType[]
{LocalTimeType.LOCAL_DATE_TIME_TYPE});
+
+ // Test with completely unsupported format
+ Assertions.assertThrows(
+ TransformException.class,
+ () ->
+ runSql(
+ "select PARSEDATETIME('2024-06-15',
'dd/MM/yyyy') as dt from dual",
+ rowType,
+ LocalDateTime.now()));
+ }
+
+ @Test
+ public void testParseDateTimeWithMalformedInput() {
+ SeaTunnelRowType rowType =
+ new SeaTunnelRowType(
+ new String[] {"dummy"},
+ new SeaTunnelDataType[]
{LocalTimeType.LOCAL_DATE_TIME_TYPE});
+
+ // Test with malformed input string
+ Assertions.assertThrows(
+ TransformException.class,
+ () ->
+ runSql(
+ "select PARSEDATETIME('not-a-date',
'yyyy-MM-dd') as dt from dual",
+ rowType,
+ LocalDateTime.now()));
+ }
+
+ @Test
+ public void testToDateWithVariousFormats() {
+ SeaTunnelRowType rowType =
+ new SeaTunnelRowType(
+ new String[] {"dummy"},
+ new SeaTunnelDataType[]
{LocalTimeType.LOCAL_DATE_TIME_TYPE});
+
+ // TO_DATE is an alias for PARSEDATETIME
+ SeaTunnelRow row1 =
+ runSql(
+ "select TO_DATE('2024-06-15', 'yyyy-MM-dd') as dt from
dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(LocalDate.of(2024, 6, 15), row1.getField(0));
+
+ SeaTunnelRow row2 =
+ runSql(
+ "select TO_DATE('2024-06-15 14:30:45', 'yyyy-MM-dd
HH:mm:ss') as dt from dual",
+ rowType,
+ LocalDateTime.now());
+ Assertions.assertEquals(LocalDateTime.of(2024, 6, 15, 14, 30, 45),
row2.getField(0));
+ }
Review Comment:
It seems to be duplicated with `testParseDateTimeWithAllDateFormats()`,
`testParseDateTimeWithAllTimeFormats()`.
##########
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/sql/zeta/ZetaDateTimeFormatTest.java:
##########
@@ -0,0 +1,177 @@
+/*
+ * 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.transform.sql.zeta;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Optional;
+
+public class ZetaDateTimeFormatTest {
+
+ @Test
+ public void testFromPatternWithAllDateTimeFormats() {
+ // DATETIME_STANDARD
+ Optional<ZetaDateTimeFormat> format1 =
+ ZetaDateTimeFormat.fromPattern("yyyy-MM-dd HH:mm:ss");
+ Assertions.assertTrue(format1.isPresent());
+ Assertions.assertEquals(ZetaDateTimeFormat.DATETIME_STANDARD,
format1.get());
+ Assertions.assertEquals(ZetaDateTimeFormat.FormatType.DATETIME,
format1.get().getType());
+
+ // DATETIME_WITH_MILLIS
+ Optional<ZetaDateTimeFormat> format2 =
+ ZetaDateTimeFormat.fromPattern("yyyy-MM-dd HH:mm:ss.SSS");
+ Assertions.assertTrue(format2.isPresent());
+ Assertions.assertEquals(ZetaDateTimeFormat.DATETIME_WITH_MILLIS,
format2.get());
+ Assertions.assertEquals(ZetaDateTimeFormat.FormatType.DATETIME,
format2.get().getType());
+
+ // DATETIME_ISO8601
+ Optional<ZetaDateTimeFormat> format3 =
+ ZetaDateTimeFormat.fromPattern("yyyy-MM-dd'T'HH:mm:ss");
+ Assertions.assertTrue(format3.isPresent());
+ Assertions.assertEquals(ZetaDateTimeFormat.DATETIME_ISO8601,
format3.get());
+ Assertions.assertEquals(ZetaDateTimeFormat.FormatType.DATETIME,
format3.get().getType());
+
+ // DATETIME_ISO8601_WITH_MILLIS
+ Optional<ZetaDateTimeFormat> format4 =
+ ZetaDateTimeFormat.fromPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");
+ Assertions.assertTrue(format4.isPresent());
+
Assertions.assertEquals(ZetaDateTimeFormat.DATETIME_ISO8601_WITH_MILLIS,
format4.get());
+ Assertions.assertEquals(ZetaDateTimeFormat.FormatType.DATETIME,
format4.get().getType());
+ }
+
+ @Test
+ public void testFromPatternWithAllDateFormats() {
+ // DATE_ISO8601
+ Optional<ZetaDateTimeFormat> format1 =
ZetaDateTimeFormat.fromPattern("yyyy-MM-dd");
+ Assertions.assertTrue(format1.isPresent());
+ Assertions.assertEquals(ZetaDateTimeFormat.DATE_ISO8601,
format1.get());
+ Assertions.assertEquals(ZetaDateTimeFormat.FormatType.DATE,
format1.get().getType());
+ }
+
+ @Test
+ public void testFromPatternWithAllTimeFormats() {
+ // TIME_STANDARD
+ Optional<ZetaDateTimeFormat> format1 =
ZetaDateTimeFormat.fromPattern("HH:mm:ss");
+ Assertions.assertTrue(format1.isPresent());
+ Assertions.assertEquals(ZetaDateTimeFormat.TIME_STANDARD,
format1.get());
+ Assertions.assertEquals(ZetaDateTimeFormat.FormatType.TIME,
format1.get().getType());
+
+ // TIME_WITH_MILLIS
+ Optional<ZetaDateTimeFormat> format2 =
ZetaDateTimeFormat.fromPattern("HH:mm:ss.SSS");
+ Assertions.assertTrue(format2.isPresent());
+ Assertions.assertEquals(ZetaDateTimeFormat.TIME_WITH_MILLIS,
format2.get());
+ Assertions.assertEquals(ZetaDateTimeFormat.FormatType.TIME,
format2.get().getType());
+ }
+
+ @Test
+ public void testFromPatternWithInvalidFormat() {
+ Optional<ZetaDateTimeFormat> format =
ZetaDateTimeFormat.fromPattern("invalid_pattern");
+
+ Assertions.assertFalse(format.isPresent());
+ }
+
+ @Test
+ public void testFromPatternWithNullFormat() {
+ Optional<ZetaDateTimeFormat> format =
ZetaDateTimeFormat.fromPattern(null);
+
+ Assertions.assertFalse(format.isPresent());
+ }
+
+ @Test
+ public void testAllDateTimeFormatsHaveCorrectType() {
+ Assertions.assertEquals(
+ ZetaDateTimeFormat.FormatType.DATETIME,
+ ZetaDateTimeFormat.DATETIME_STANDARD.getType());
+ Assertions.assertEquals(
+ ZetaDateTimeFormat.FormatType.DATETIME,
+ ZetaDateTimeFormat.DATETIME_WITH_MILLIS.getType());
+ Assertions.assertEquals(
+ ZetaDateTimeFormat.FormatType.DATETIME,
+ ZetaDateTimeFormat.DATETIME_ISO8601.getType());
+ Assertions.assertEquals(
+ ZetaDateTimeFormat.FormatType.DATETIME,
+ ZetaDateTimeFormat.DATETIME_ISO8601_WITH_MILLIS.getType());
+ }
+
+ @Test
+ public void testAllDateFormatsHaveCorrectType() {
+ Assertions.assertEquals(
+ ZetaDateTimeFormat.FormatType.DATE,
ZetaDateTimeFormat.DATE_ISO8601.getType());
+ }
+
+ @Test
+ public void testAllTimeFormatsHaveCorrectType() {
+ Assertions.assertEquals(
+ ZetaDateTimeFormat.FormatType.TIME,
ZetaDateTimeFormat.TIME_STANDARD.getType());
+ Assertions.assertEquals(
+ ZetaDateTimeFormat.FormatType.TIME,
ZetaDateTimeFormat.TIME_WITH_MILLIS.getType());
+ }
+
+ @Test
+ public void testGetPatternForAllFormats() {
+ Assertions.assertEquals(
+ "yyyy-MM-dd HH:mm:ss",
ZetaDateTimeFormat.DATETIME_STANDARD.getPattern());
+ Assertions.assertEquals(
+ "yyyy-MM-dd HH:mm:ss.SSS",
ZetaDateTimeFormat.DATETIME_WITH_MILLIS.getPattern());
+ Assertions.assertEquals(
+ "yyyy-MM-dd'T'HH:mm:ss",
ZetaDateTimeFormat.DATETIME_ISO8601.getPattern());
+ Assertions.assertEquals(
+ "yyyy-MM-dd'T'HH:mm:ss.SSS",
+ ZetaDateTimeFormat.DATETIME_ISO8601_WITH_MILLIS.getPattern());
+
+ Assertions.assertEquals("yyyy-MM-dd",
ZetaDateTimeFormat.DATE_ISO8601.getPattern());
+
+ Assertions.assertEquals("HH:mm:ss",
ZetaDateTimeFormat.TIME_STANDARD.getPattern());
+ Assertions.assertEquals("HH:mm:ss.SSS",
ZetaDateTimeFormat.TIME_WITH_MILLIS.getPattern());
+ }
+
+ @Test
+ public void testFromPatternWithISO8601Formats() {
+ Optional<ZetaDateTimeFormat> format1 =
+ ZetaDateTimeFormat.fromPattern("yyyy-MM-dd'T'HH:mm:ss");
+ Assertions.assertTrue(format1.isPresent());
+ Assertions.assertEquals(ZetaDateTimeFormat.DATETIME_ISO8601,
format1.get());
+
+ Optional<ZetaDateTimeFormat> format2 =
+ ZetaDateTimeFormat.fromPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");
+ Assertions.assertTrue(format2.isPresent());
+
Assertions.assertEquals(ZetaDateTimeFormat.DATETIME_ISO8601_WITH_MILLIS,
format2.get());
+ }
Review Comment:
It seems to be duplicated with `testFromPatternWithAllDateTimeFormats()`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]