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


##########
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:
   for bit-type with size <= 1 of mysql column, users usually use this column 
to express false or true, so it make sense to be recognized boolean type in 
hive.
   
   for bit-type with size >1 of mysql column, users may want to express 
different semantics, eg weekly working calendar, bit(7) , and in this case we 
can not simply convert bit(7) to boolean type. I convert this bit(n) to bigint 
in hive, eg **b'111000' will be read as 56**.
   
   in this pr, i  added qtest to select bit datatype, but HIVE-26192 blocked 
me, i hope you can give advice about HIVE-26192。
   
   > But also to be able to read this datatype, should we read as "select 
bin(col)" while reading from remote  table?
   
   I think it is diffcult and not worth to read as "select bin(col)".  Becaue 
if we want do this, we may need to mak type check when executing query and then 
convert column type to bit.  Also, hive can not recognize bit type, and i think 
hive will compile failed with bit type before the query is submited to mysql.  
That's just my basic thought. 
   
    
   In addtion, i have checked  the presto and spark code. presto will convert 
all bit type to bolean. Spark have the similar ideas with this pr. I think 
spark idea is more reasonable.
   
https://github.com/trinodb/trino/blob/543ae143cadeb47ab03af4197dae9d00ff5baf7c/plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java#L377-L379
   
   
https://github.com/apache/spark/blob/7309e76d8b95e306d6f3d2f611316b748949e9cf/sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala#L64-#L71
   



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