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

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_r208167533
 
 

 ##########
 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),
 
 Review comment:
   We should test the full matrix. MONTH on date, timestamp is missing.
   
   Maybe we can make the tests more generic similar to timestamp add. We should 
test every combination of unit, type, type.

----------------------------------------------------------------
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:
us...@infra.apache.org


> 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