vlsi 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_r260918529
########## 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: @ijokarumawak , this is wrong. "EXPECTED" value must not come from a system under test. You should either hard-code the expected value (which is preferred) or compute it with a "simple to understand" approach. ---------------------------------------------------------------- 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 With regards, Apache Git Services