[GitHub] [flink] walterddr commented on a change in pull request #8248: [FLINK-12309][JDBC] JDBCOoutputFormat and JDBCAppendTableSink float behavior is not align
walterddr commented on a change in pull request #8248: [FLINK-12309][JDBC] JDBCOoutputFormat and JDBCAppendTableSink float behavior is not align URL: https://github.com/apache/flink/pull/8248#discussion_r279415433 ## File path: flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormat.java ## @@ -160,7 +160,11 @@ public void writeRecord(Row row) throws IOException { break; case java.sql.Types.FLOAT: case java.sql.Types.DOUBLE: - upload.setDouble(index + 1, (double) row.getField(index)); + if (row.getField(index).getClass() == Float.class) { Review comment: I am not sure this is the right approach. shouldn't we do something like: ``` case java.sql.Types.FLOAT: upload.setFloat(index + 1, (float) row.getField(index)); break; case java.sql.Types.DOUBLE: upload.setDouble(index + 1, (double) row.getField(index)); break; ``` that would make more sense to me since the row is float, the type mapping is also float. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] walterddr commented on a change in pull request #8248: [FLINK-12309][JDBC] JDBCOoutputFormat and JDBCAppendTableSink float behavior is not align
walterddr commented on a change in pull request #8248: [FLINK-12309][JDBC] JDBCOoutputFormat and JDBCAppendTableSink float behavior is not align URL: https://github.com/apache/flink/pull/8248#discussion_r279414601 ## File path: flink-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormatTest.java ## @@ -133,6 +133,32 @@ public void testExceptionOnInvalidType() throws IOException { jdbcOutputFormat.writeRecord(row); } + @Test(expected = RuntimeException.class) + public void testCastFloatToDoubleType() throws IOException { + jdbcOutputFormat = JDBCOutputFormat.buildJDBCOutputFormat() + .setDrivername(DRIVER_CLASS) + .setDBUrl(DB_URL) + .setQuery(String.format(INSERT_TEMPLATE, INPUT_TABLE)) + .setSqlTypes(new int[] { + Types.INTEGER, + Types.VARCHAR, + Types.VARCHAR, + Types.FLOAT, + Types.VARCHAR}) + .finish(); + jdbcOutputFormat.open(0, 1); + + Row row = new Row(5); + row.setField(0, 4); + row.setField(1, "hello"); + row.setField(2, "world"); + row.setField(3, 0.99f); // jdbcOutputFormat will cast float to double Review comment: I usually avoid trailing comments (it's already pretty self-explanatory from your test function name 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] walterddr commented on a change in pull request #8248: [FLINK-12309][JDBC] JDBCOoutputFormat and JDBCAppendTableSink float behavior is not align
walterddr commented on a change in pull request #8248: [FLINK-12309][JDBC] JDBCOoutputFormat and JDBCAppendTableSink float behavior is not align URL: https://github.com/apache/flink/pull/8248#discussion_r279414202 ## File path: flink-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormatTest.java ## @@ -133,6 +133,32 @@ public void testExceptionOnInvalidType() throws IOException { jdbcOutputFormat.writeRecord(row); } + @Test(expected = RuntimeException.class) Review comment: I am assuming you are trying to catch the `"imthewrongtype"` on the last column. but if the jdbc cast float to double fails. It will throw the same exception and the test will still pass. I suggest let this pass by setting the last field to `INTEGER` 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: us...@infra.apache.org With regards, Apache Git Services