You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/03/08 04:57:23 UTC

[GitHub] [calcite] hsyuan commented on a change in pull request #1077: [CALCITE-2818] EXTRACT returns wrong results for DATE and TIMESTAMP values before epoch

hsyuan commented on a change in pull request #1077: [CALCITE-2818] EXTRACT returns wrong results for DATE and TIMESTAMP values before epoch
URL: https://github.com/apache/calcite/pull/1077#discussion_r263665447
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
 ##########
 @@ -6713,6 +6713,57 @@ private void checkNullOperand(SqlTester tester, String op) {
         "extract(microsecond from cast(null as time))");
   }
 
+  @Test public void testExtractWithDatesBeforeUnixEpoch() {
+    tester.checkScalar(
+        "extract(year from TIMESTAMP '1970-01-01 00:00:00')",
+        "1970",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(year from TIMESTAMP '1969-12-31 10:13:17')",
+        "1969",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(quarter from TIMESTAMP '1969-12-31 08:13:17')",
+        "4",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(quarter from TIMESTAMP '1969-5-31 21:13:17')",
+        "2",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(month from TIMESTAMP '1969-12-31 00:13:17')",
+        "12",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(day from TIMESTAMP '1969-12-31 12:13:17')",
+        "31",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(week from TIMESTAMP '1969-2-23 01:23:45')",
+        "8",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(hour from TIMESTAMP '1969-12-31 21:13:17.357')",
+        "21",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(minute from TIMESTAMP '1969-12-31 21:13:17.357')",
+        "13",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(second from TIMESTAMP '1969-12-31 21:13:17.357')",
+        "17",
+        "BIGINT NOT NULL");
+    tester.checkScalar(
+        "extract(millisecond from TIMESTAMP '1969-12-31 21:13:17.357')",
+        "17357",
 
 Review comment:
   I think 17357 is correct. Postgres also gives this answer.

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


With regards,
Apache Git Services