leonardBang commented on a change in pull request #15133:
URL: https://github.com/apache/flink/pull/15133#discussion_r598846593



##########
File path: 
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/expressions/TemporalTypesTest.scala
##########
@@ -1370,6 +1371,124 @@ class TemporalTypesTest extends ExpressionTestBase {
     testSqlApi(
       "TIMESTAMPDIFF(MONTH, DATE '2019-09-01', DATE '2016-08-01')",
       "-37")
+    testSqlApi(
+      "TIMESTAMPDIFF(MONTH, TIMESTAMP '2021-01-04 00:00:00', DATE 
'2021-02-04')",
+      "1")
+    testSqlApi(
+      "TIMESTAMPDIFF(MONTH, DATE '2020-01-04', TIMESTAMP '2021-02-04 
12:00:00')",
+      "13")
+    testSqlApi(
+      "TIMESTAMPDIFF(MONTH, TIMESTAMP '2021-01-04 00:00:00', TIME '00:00:00')",
+      "-612")
+    testSqlApi(
+      "TIMESTAMPDIFF(MONTH, TIME '00:00:00', TIMESTAMP '2021-02-04 12:00:00')",
+      "613")
+    testSqlApi(
+      "TIMESTAMPDIFF(MONTH, DATE '2021-01-04', TIME '00:00:00')",
+      "-612")
+    testSqlApi(
+      "TIMESTAMPDIFF(MONTH, TIME '00:00:00', DATE '2021-02-04')",
+      "613")
+  }
+
+  @Test
+  def testTimestampLtzArithmetic(): Unit = {
+    // TIMESTAMP_LTZ +/- INTERVAL should support nanosecond
+    testSqlApi(
+      s"${timestampTz("1970-02-01 00:00:00.123456789")} + INTERVAL '1' YEAR",
+      "1971-02-01 00:00:00.123456789")
+
+    testSqlApi(
+      s"${timestampTz("1970-02-01 00:00:00.123456789")} - INTERVAL '1' MONTH",
+      "1970-01-01 00:00:00.123456789")
+
+    testSqlApi(
+      s"${timestampTz("1970-02-01 00:00:00.123456789")} + INTERVAL '1' DAY",
+      "1970-02-02 00:00:00.123456789")
+
+    testSqlApi(
+      s"${timestampTz("1970-02-01 00:00:00.123456789")} - INTERVAL '1' HOUR",
+      "1970-01-31 23:00:00.123456789")
+
+    testSqlApi(
+      s"${timestampTz("1970-02-01 00:00:00.123456789")} + INTERVAL '1' MINUTE",
+      "1970-02-01 00:01:00.123456789")
+
+    testSqlApi(
+      s"${timestampTz("1970-02-01 00:00:00.123456789")} - INTERVAL '1' SECOND",
+      "1970-01-31 23:59:59.123456789")
+
+    // test TIMESTAMPDIFF for TIMESTAMP_LTZ type
+    testSqlApi(
+      s"TIMESTAMPDIFF(YEAR, ${timestampTz("1970-01-01 00:00:00.123456789")}," +
+        s" ${timestampTz("1971-01-02 01:02:03.123456789")})",
+      "1")
+
+    testSqlApi(
+      s"TIMESTAMPDIFF(MONTH, ${timestampTz("1970-01-01 00:00:00.123456789")}," 
+
+        s" ${timestampTz("1971-01-02 01:02:03.123456789")})",
+      "12")
+
+    testSqlApi(
+      s"TIMESTAMPDIFF(DAY, ${timestampTz("1970-01-01 00:00:00.123")}," +
+        s" ${timestampTz("1971-01-02 01:02:03.123")})",
+      "366")
+
+    testSqlApi(
+      s"TIMESTAMPDIFF(HOUR, ${timestampTz("1970-01-01 00:00:00.123")}," +
+        s" ${timestampTz("1970-01-01 01:02:03.123")})",
+      "1")
+
+    testSqlApi(
+      s"TIMESTAMPDIFF(MINUTE, ${timestampTz("1970-01-01 01:02:03.123")}," +
+        s" ${timestampTz("1970-01-01 00:00:00")})",
+      "-62")

Review comment:
       no, you can look `TIMESTAMPDIFF(MINUTE , TIMESTAMP, TIMESTAMP)`




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to