You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2021/08/16 09:55:24 UTC

[GitHub] [phoenix] richardantal commented on a change in pull request #1284: PHOENIX-6486 Phoenix uses inconsistent chronologies internally, breaking pre-Gregorian date handling

richardantal commented on a change in pull request #1284:
URL: https://github.com/apache/phoenix/pull/1284#discussion_r689397287



##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
##########
@@ -1939,6 +1941,99 @@ public void testDateFormatTimeZone()throws Exception {
         }
     }
 
+    private String getFormattedDate(List<String> dateList) {
+        return String.join("-", dateList.subList(0, 3)) + " "
+                + String.join(":", dateList.subList(3, 6)) + "." + dateList.get(6);
+    }
+
+    @Test
+    public void testAncientDates() throws Exception {
+
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(url, props);
+        Statement stmt = conn.createStatement();
+        String tableName = generateUniqueName();
+
+        List<String> date1list = Arrays.asList("0010", "10", "10", "10", "10", "10", "111");
+        List<String> date2list = Arrays.asList("1000", "02", "03", "04", "05", "06", "000");
+        List<String> date3list = Arrays.asList("0001", "12", "31", "23", "59", "59", "000");
+        List<List<String>> dateLists = Arrays.asList(date1list, date2list, date3list, date2list);
+
+        String date1 = getFormattedDate(date1list); // 0010-10-10 10:10:10.111
+        String date2 = getFormattedDate(date2list); // 1000-02-03 04:05:06.000
+        String date3 = getFormattedDate(date3list); // 0001-12-31 23:59:59.000
+        List<String> dates = Arrays.asList(date1, date2, date3, date2);
+
+
+        //TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC')
+        stmt.execute("CREATE TABLE " + tableName + " ( id INTEGER not null PRIMARY KEY," +
+                " date DATE, time TIME, timestamp TIMESTAMP)");
+
+        stmt.execute("UPSERT INTO " + tableName + " VALUES(1, TO_DATE('" + date1
+                + "'), TO_TIME('" + date1 + "'), TO_TIMESTAMP('" + date1 + "'))");
+
+        stmt.execute("UPSERT INTO " + tableName + " VALUES(2, TO_DATE('" + date2
+                + "'), TO_TIME('" + date2 + "'), TO_TIMESTAMP('" + date2 + "'))");
+
+        String f = " GMT', 'yyyy-MM-dd HH:mm:ss.SSS z', 'UTC";
+        stmt.execute("UPSERT INTO " + tableName + " VALUES(4, TO_DATE('" + date2 + f
+                + "'), TO_TIME('" + date2 + f + "'), TO_TIMESTAMP('" + date2 + f + "'))");

Review comment:
       I'd like to have test for both PreparedStatements and execute statements as well.




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

To unsubscribe, e-mail: issues-unsubscribe@phoenix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org