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/04/09 02:03:03 UTC

[GitHub] [calcite] ijokarumawak commented on a change in pull request #971: [CALCITE-1703] Functions on TIMESTAMP column throws ClassCastException

ijokarumawak commented on a change in pull request #971: [CALCITE-1703] Functions on TIMESTAMP column throws ClassCastException
URL: https://github.com/apache/calcite/pull/971#discussion_r273301077
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/test/ObjectArrayTableTest.java
 ##########
 @@ -241,6 +244,35 @@ private void withJavaSqlDateTypes(TestWithConnection test) throws SQLException {
     });
 
   }
+
+  /**
+   * Test to confirm java.sql.Timestamp can be casted to Timestamp with different precision.
+   * The cast should be done the same as with TIMESTAMP literal.
+   */
+  @Test public void testCastTimestampToTimestamp() throws SQLException {
+
+    withJavaSqlDateTypes(connection -> {
+
+      Statement statement = connection.createStatement();
+      final String sql = "select %s as EXPECTED, %s as ACTUAL from \"java_sql_date_types\"";
+
+      for (int i = 3; i >= 0; i--) {
+        final String castTo = format(Locale.ROOT, "TIMESTAMP(%d)", i);
+
+        final String expected = format(Locale.ROOT,
+            "cast(TIMESTAMP '2018-12-14 18:29:34.123' as %s)", castTo);
+        final String actual = format(Locale.ROOT, "cast(\"ts\" as %s)", castTo);
+        final ResultSet resultSet = statement.executeQuery(
+            format(Locale.ROOT, sql, expected, actual));
+        resultSet.next();
+        assertEquals(format(Locale.ROOT, "cast(java.sql.Timestamp as %s)", castTo),
+            resultSet.getTimestamp(1), resultSet.getTimestamp(2));
 
 Review comment:
   Changed to use hard-coded expected values.

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