zhangbutao commented on code in PR #3276:
URL: https://github.com/apache/hive/pull/3276#discussion_r957943881


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/dataconnector/jdbc/MySQLConnectorProvider.java:
##########
@@ -90,10 +90,20 @@ protected String getDataType(String dbDataType, int size) {
     // map any db specific types here.
     switch (dbDataType.toLowerCase())
     {
+    case "bit":
+      return toHiveBitType(size);
     default:
       mappedType = ColumnType.VOID_TYPE_NAME;
       break;
     }
     return mappedType;
   }
+
+  private String toHiveBitType(int size) {
+    if (size <= 1) {
+      return ColumnType.BOOLEAN_TYPE_NAME;
+    } else {
+      return ColumnType.BIGINT_TYPE_NAME;

Review Comment:
   @dengzhhu653 @nrg4878 Thanks for your suggestion.
   Actually, i have tried to convert MySQL's bit datatype to hive's binary, but 
did not get expected restult. In this case, hive stores MySQL's  bit 
values(b'111000') as binary type, and this binary values can not dispaly to 
users, that is to say users only can see a blank result.
   
   Step to test:
   1. create mysql table with bit data type in mysql:
   
![image](https://user-images.githubusercontent.com/9760681/187333226-f23705a5-50b6-40bf-b1e1-8fcecc7a065c.png)
   
   2. create jdbc-mapping table in hive:
   `   CREATE EXTERNAL TABLE jdbc_testmysqlbit`
   `(`
   `  id binary`
   `)`
   `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/testdb",`
   `"hive.sql.dbcp.username" = "user",`
   `"hive.sql.dbcp.password" = "passwd",`
   `"hive.sql.table" = "testmysqlbit",`
   `"hive.sql.dbcp.maxActive" = "1"`
   `);`
   
   3.`select * from jdbc_testmysqlbit;`  using hive beeline:
   
![image](https://user-images.githubusercontent.com/9760681/187333975-e7d6270c-e922-4088-948f-46024cbcb6e5.png)
   



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