You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tw...@apache.org on 2021/12/14 16:39:17 UTC

[flink] branch master updated: [FLINK-25304][table-planner][tests] Add tests for padding of fractional seconds

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

twalthr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new 458e798  [FLINK-25304][table-planner][tests] Add tests for padding of fractional seconds
458e798 is described below

commit 458e798f4fb6afe00bbb17d4c4530846fc5de112
Author: Marios Trivyzas <ma...@gmail.com>
AuthorDate: Tue Dec 14 15:49:12 2021 +0200

    [FLINK-25304][table-planner][tests] Add tests for padding of fractional seconds
    
    Add Unit and IT tests to validate the `0` padding of the fractional seconds
    when casting a `TIMESTAMP` or `TIMESTAMP_LTZ` to string, so that the length
    of the fractional seconds in the resulting string matches the `precision`
    specified on the source type.
    
    This closes #18106.
---
 .../planner/functions/CastFunctionITCase.java      | 14 ++++++++++-
 .../planner/functions/casting/CastRulesTest.java   | 27 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java
index eceea3c..36450b0 100644
--- a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java
+++ b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/CastFunctionITCase.java
@@ -211,8 +211,12 @@ public class CastFunctionITCase extends BuiltInFunctionTestBase {
                         // seconds are lost
                         .fromCase(TIME(5), DEFAULT_TIME, "12:34:56")
                         .fromCase(TIMESTAMP(), DEFAULT_TIMESTAMP, "2021-09-24 12:34:56.123456")
-                        .fromCase(TIMESTAMP(8), DEFAULT_TIMESTAMP, "2021-09-24 12:34:56.12345670")
+                        .fromCase(TIMESTAMP(9), DEFAULT_TIMESTAMP, "2021-09-24 12:34:56.123456700")
                         .fromCase(TIMESTAMP(4), DEFAULT_TIMESTAMP, "2021-09-24 12:34:56.1234")
+                        .fromCase(
+                                TIMESTAMP(3),
+                                LocalDateTime.parse("2021-09-24T12:34:56.1"),
+                                "2021-09-24 12:34:56.100")
                         .fromCase(TIMESTAMP(4).nullable(), null, null)
 
                         // https://issues.apache.org/jira/browse/FLINK-20869
@@ -222,6 +226,14 @@ public class CastFunctionITCase extends BuiltInFunctionTestBase {
                                 TIMESTAMP_LTZ(5),
                                 DEFAULT_TIMESTAMP_LTZ,
                                 "2021-09-25 07:54:56.12345")
+                        .fromCase(
+                                TIMESTAMP_LTZ(9),
+                                DEFAULT_TIMESTAMP_LTZ,
+                                "2021-09-25 07:54:56.123456700")
+                        .fromCase(
+                                TIMESTAMP_LTZ(3),
+                                fromLocalTZ("2021-09-24T22:34:56.1"),
+                                "2021-09-25 07:54:56.100")
                         .fromCase(INTERVAL(YEAR()), 84, "+7-00")
                         .fromCase(INTERVAL(MONTH()), 5, "+0-05")
                         .fromCase(INTERVAL(MONTH()), 123, "+10-03")
diff --git a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRulesTest.java b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRulesTest.java
index 76cd6d9..3d943ab 100644
--- a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRulesTest.java
+++ b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRulesTest.java
@@ -527,7 +527,34 @@ class CastRulesTest {
                                 fromString(String.valueOf(Double.MAX_VALUE)))
                         .fromCase(STRING(), fromString("Hello"), fromString("Hello"))
                         .fromCase(TIMESTAMP(), TIMESTAMP, TIMESTAMP_STRING)
+                        .fromCase(
+                                TIMESTAMP(9),
+                                TIMESTAMP,
+                                fromString("2021-09-24 12:34:56.123456000"))
+                        .fromCase(
+                                TIMESTAMP(7), TIMESTAMP, fromString("2021-09-24 12:34:56.1234560"))
+                        .fromCase(
+                                TIMESTAMP(3),
+                                TimestampData.fromLocalDateTime(
+                                        LocalDateTime.parse("2021-09-24T12:34:56.1")),
+                                fromString("2021-09-24 12:34:56.100"))
                         .fromCase(TIMESTAMP_LTZ(), CET_CONTEXT, TIMESTAMP, TIMESTAMP_STRING_CET)
+                        .fromCase(
+                                TIMESTAMP_LTZ(9),
+                                CET_CONTEXT,
+                                TIMESTAMP,
+                                fromString("2021-09-24 14:34:56.123456000"))
+                        .fromCase(
+                                TIMESTAMP_LTZ(7),
+                                CET_CONTEXT,
+                                TIMESTAMP,
+                                fromString("2021-09-24 14:34:56.1234560"))
+                        .fromCase(
+                                TIMESTAMP_LTZ(3),
+                                CET_CONTEXT,
+                                TimestampData.fromLocalDateTime(
+                                        LocalDateTime.parse("2021-09-24T12:34:56.1")),
+                                fromString("2021-09-24 14:34:56.100"))
                         .fromCase(DATE(), DATE, DATE_STRING)
                         .fromCase(TIME(5), TIME, TIME_STRING)
                         .fromCase(INTERVAL(YEAR()), 84, fromString("+7-00"))