[ 
https://issues.apache.org/jira/browse/FLINK-6847?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16571393#comment-16571393
 ] 

ASF GitHub Bot commented on FLINK-6847:
---------------------------------------

twalthr commented on a change in pull request #6282: [FLINK-6847][FLINK-6813] 
[table] TimestampDiff table api and sql support
URL: https://github.com/apache/flink/pull/6282#discussion_r208169001
 
 

 ##########
 File path: 
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/ScalarFunctionsTest.scala
 ##########
 @@ -1943,6 +1943,147 @@ class ScalarFunctionsTest extends ScalarTypesTestBase {
       "false")
   }
 
+  @Test
+  def testTimestampDiff(): Unit = {
+    testTableApi(
+      "2018-07-05 11:11:11".toTimestamp - "2018-07-03 11:11:11".toTimestamp,
+      "'2018-07-05 11:11:11'.toTimestamp - '2018-07-03 11:11:11'.toTimestamp",
+      "172800000"
+    )
+
+    testTableApi(
+      "2018-07-05 11:11:11".toTimestamp - "2018-07-03".toDate,
+      "'2018-07-05 11:11:11'.toTimestamp - '2018-07-03'.toDate",
+      "213071000"
+    )
+
+    testTableApi(
+      "2018-07-03".toDate - "2018-07-05 11:11:11".toTimestamp,
+      "'2018-07-03'.toDate - '2018-07-05 11:11:11'.toTimestamp",
+      "-213071000"
+    )
+
+    testTableApi(
+      "2018-07-05".toDate - "2018-07-03".toDate,
+      "'2018-07-05'.toDate - '2018-07-03'.toDate",
+      "172800000"
+    )
+
+    testAllApis(
+      timestampDiff(
+        TimeIntervalUnit.DAY,
+        "2018-07-03 11:11:11".toTimestamp,
+        "2018-07-05 11:11:11".toTimestamp),
+      "timestampDiff(DAY, '2018-07-03 11:11:11'.toTimestamp," +
+        "'2018-07-05 11:11:11'.toTimestamp)",
+      "TIMESTAMPDIFF(DAY, " +
+        "TIMESTAMP '2018-07-03 11:11:11', TIMESTAMP '2018-07-05 11:11:11')",
+      "2")
+
+    testAllApis(
+      timestampDiff(TimeIntervalUnit.DAY, "2016-06-15".toDate, "2016-06-16 
11:11:11".toTimestamp),
+      "timestampDiff(DAY, '2016-06-15'.toDate, '2016-06-16 
11:11:11'.toTimestamp)",
+      "TIMESTAMPDIFF(DAY, DATE '2016-06-15', TIMESTAMP '2016-06-16 11:11:11')",
+      "1")
+
+    testAllApis(
+      timestampDiff(TimeIntervalUnit.DAY, "2016-06-15 11:00:00".toTimestamp, 
"2016-06-19".toDate),
+      "timestampDiff(DAY, '2016-06-15 11:00:00'.toTimestamp, 
'2016-06-19'.toDate)",
+      "TIMESTAMPDIFF(DAY, TIMESTAMP '2016-06-15 11:00:00', DATE '2016-06-19')",
+      "3")
+
+    testAllApis(
+      timestampDiff(
+          TimeIntervalUnit.MONTH,
+          "2018-07-03 11:11:11".toTimestamp,
+          "2018-09-05 11:11:11".toTimestamp),
+      "timestampDiff(MONTH, " +
+        "'2018-07-03 11:11:11'.toTimestamp, '2018-09-05 
11:11:11'.toTimestamp)",
+      "TIMESTAMPDIFF(MONTH, " +
+        "TIMESTAMP '2018-07-03 11:11:11', TIMESTAMP '2018-09-05 11:11:11')",
+      "2")
+
+    testAllApis(
+      timestampDiff(TimeIntervalUnit.MONTH, "2016-06-15".toDate, 
"2016-04-18".toDate),
+      "TIMESTAMPDIFF(MONTH, '2016-06-15'.toDate, '2016-04-18'.toDate)",
+      "TIMESTAMPDIFF(MONTH, DATE '2016-06-15', DATE '2016-04-18')",
+      "-1")
+
+    testAllApis(
+      timestampDiff(TimeIntervalUnit.MONTH, "2016-06-15".toDate, 
"2016-04-14".toDate),
+      "timestampDiff(MONTH, '2016-06-15'.toDate, '2016-04-14'.toDate)",
+      "TIMESTAMPDIFF(MONTH, DATE '2016-06-15', DATE '2016-04-14')",
+      "-2")
+
+    testAllApis(
+      timestampDiff(TimeIntervalUnit.YEAR, "2016-06-15".toDate, "2019-06-16 
11:11:11".toTimestamp),
+      "timestampDiff(YEAR, '2016-06-15'.toDate, '2019-06-16 
11:11:11'.toTimestamp)",
+      "TIMESTAMPDIFF(YEAR, DATE '2016-06-15', TIMESTAMP '2019-06-16 
11:11:11')",
+      "3")
+
+    testAllApis(
+      timestampDiff(TimeIntervalUnit.YEAR, "2016-06-15 11:00:00".toTimestamp, 
"2013-06-19".toDate),
+      "timestampDiff(YEAR, '2016-06-15 11:00:00'.toTimestamp, 
'2013-06-19'.toDate)",
+      "TIMESTAMPDIFF(YEAR, TIMESTAMP '2016-06-15 11:00:00', DATE 
'2013-06-19')",
+      "-2")
+
+    testAllApis(
+      timestampDiff(TimeIntervalUnit.DAY, "2016-06-15".toDate, 
"2016-06-18".toDate),
+      "timestampDiff(DAY, '2016-06-15'.toDate, '2016-06-18'.toDate)",
+      "TIMESTAMPDIFF(DAY, DATE '2016-06-15', DATE '2016-06-18')",
+      "3")
+
+    testAllApis(
+      timestampDiff(
+        TimeIntervalUnit.HOUR,
+        "2018-07-03 11:11:11".toTimestamp,
+        "2018-07-04 12:12:11".toTimestamp),
+      "timestampDiff(HOUR, '2018-07-03 11:11:11'.toTimestamp," +
+        "'2018-07-04 12:12:11'.toTimestamp)",
+      "TIMESTAMPDIFF(HOUR, " +
+        "TIMESTAMP '2018-07-03 11:11:11', TIMESTAMP '2018-07-04 12:12:11')",
+      "25")
+
+    testAllApis(
+      timestampDiff(
+        TimeIntervalUnit.HOUR,
+        "2018-07-03 11:11:11".toTimestamp,
+        "2018-07-04 12:10:11".toTimestamp),
+      "timestampDiff(HOUR, '2018-07-03 11:11:11'.toTimestamp," +
+        "'2018-07-04 12:10:11'.toTimestamp)",
+      "TIMESTAMPDIFF(HOUR, " +
+        "TIMESTAMP '2018-07-03 11:11:11', TIMESTAMP '2018-07-04 12:10:11')",
+      "24")
+
+    testAllApis(
+      timestampDiff(
+        TimeIntervalUnit.MINUTE,
+        "2018-07-03 11:11:11".toTimestamp,
+        "2018-07-03 12:10:11".toTimestamp),
+      "timestampDiff(MINUTE, '2018-07-03 11:11:11'.toTimestamp," +
+        "'2018-07-03 12:10:11'.toTimestamp)",
+      "TIMESTAMPDIFF(MINUTE, " +
+        "TIMESTAMP '2018-07-03 11:11:11', TIMESTAMP '2018-07-03 12:10:11')",
+      "59")
+
+    testAllApis(
+      timestampDiff(
+        TimeIntervalUnit.SECOND,
+        "2018-07-03 11:11:11".toTimestamp,
+        "2018-07-03 11:12:12".toTimestamp),
+      "timestampDiff(SECOND, '2018-07-03 11:11:11'.toTimestamp," +
+        "'2018-07-03 11:12:12'.toTimestamp)",
+      "TIMESTAMPDIFF(SECOND, " +
+        "TIMESTAMP '2018-07-03 11:11:11', TIMESTAMP '2018-07-03 11:12:12')",
+      "61")
+
+    testAllApis(
 
 Review comment:
   Add SQL specific tests for the SQL TSI units.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add TIMESTAMPDIFF supported in TableAPI
> ---------------------------------------
>
>                 Key: FLINK-6847
>                 URL: https://issues.apache.org/jira/browse/FLINK-6847
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Table API & SQL
>    Affects Versions: 1.4.0
>            Reporter: sunjincheng
>            Priority: Major
>              Labels: pull-request-available, starter
>
> see FLINK-6813



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to