zabetak commented on code in PR #3709:
URL: https://github.com/apache/hive/pull/3709#discussion_r1007945976


##########
jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/DBRecordWritable.java:
##########
@@ -61,16 +60,30 @@ public void write(PreparedStatement statement) throws 
SQLException {
     if (columnValues == null) {
       throw new SQLException("No data available to be written");
     }
-    ParameterMetaData parameterMetaData = statement.getParameterMetaData();
     for (int i = 0; i < columnValues.length; i++) {
       Object value = columnValues[i];
-      if ((parameterMetaData.getParameterType(i + 1) == Types.CHAR) && value 
!= null && value instanceof Boolean) {
+      if ((checkParamMeta(statement) && 
statement.getParameterMetaData().getParameterType(i + 1) == Types.CHAR)
+          && value != null && value instanceof Boolean) {
         value = ((Boolean) value).booleanValue() ? "1" : "0";
       }
       statement.setObject(i + 1, value);
     }
   }
 
+  private Boolean checkParamMeta(PreparedStatement statement) throws 
SQLException {
+    String dbType = 
statement.getConnection().toString().split(":")[1].toUpperCase();

Review Comment:
   Relying on `getConnection().toString()` is risky since the result can change 
at any time without notice. Moreover, I am not sure if the snippet here is 
gonna work for every supported database.



##########
jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/DBRecordWritable.java:
##########
@@ -61,16 +60,30 @@ public void write(PreparedStatement statement) throws 
SQLException {
     if (columnValues == null) {
       throw new SQLException("No data available to be written");
     }
-    ParameterMetaData parameterMetaData = statement.getParameterMetaData();
     for (int i = 0; i < columnValues.length; i++) {
       Object value = columnValues[i];
-      if ((parameterMetaData.getParameterType(i + 1) == Types.CHAR) && value 
!= null && value instanceof Boolean) {
+      if ((checkParamMeta(statement) && 
statement.getParameterMetaData().getParameterType(i + 1) == Types.CHAR)
+          && value != null && value instanceof Boolean) {
         value = ((Boolean) value).booleanValue() ? "1" : "0";
       }
       statement.setObject(i + 1, value);

Review Comment:
   Here are doing a conversion based on expected and actual type. Instead of 
relying on parameterMetaData which may not be available in every JDBC driver 
can't we do the conversion earlier. E.g., when we setup `columnValues`?



##########
ql/src/test/queries/clientpositive/jdbc_table_dml_mysql.q:
##########
@@ -0,0 +1,15 @@
+--! qt:database:mysql:q_test_country_table.sql
+
+CREATE EXTERNAL TABLE country (id int, name varchar(20))
+    STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
+TBLPROPERTIES (
+    "hive.sql.database.type" = "MYSQL",
+    "hive.sql.jdbc.driver" = "com.mysql.jdbc.Driver",
+    "hive.sql.jdbc.url" = "jdbc:mysql://localhost:3306/qtestDB",
+    "hive.sql.dbcp.username" = "root",
+    "hive.sql.dbcp.password" = "qtestpassword",
+    "hive.sql.table" = "country"
+    );
+
+INSERT INTO country VALUES (8, 'Hungary');
+SELECT * FROM country;

Review Comment:
   Please add new line at the end of file (see 
https://unix.stackexchange.com/questions/18743/whats-the-point-in-adding-a-new-line-to-the-end-of-a-file).



##########
ql/src/test/queries/clientpositive/jdbc_handler.q:
##########
@@ -1,5 +1,4 @@
 --! qt:dataset:src
---! qt:disabled:flaky HIVE-23709

Review Comment:
   We have no proof that this is not flaky anymore so leave it disabled for the 
time-being and add new tests if necessary.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to