最近使用sqoop从mysql导入数据的时候发现tinyint(1)的字段内容在hive中变成了true、false的布尔类型,但是tinyint(2)的却没有。
Sqoop在抽取数据到Hive或者HDFS时,会自动将类型为tinyint(1)的列转为boolean类型,这就是导致抽取到Hive或HDFS中的数据中只有true和false的原因。因为默认情况下,MySQL JDBC connector 会将Tinyint(1)映射为java.sql.Types.BIT类型,而Sqoop默认会映射为Boolean类型。
解决方案:
27.2.5. MySQL: Import of TINYINT(1) from MySQL behaves strangely
Problem: Sqoop is treating TINYINT(1) columns as booleans, which is for example causing issues with HIVE import. This is because by default the MySQL JDBC connector maps the TINYINT(1) to java.sql.Types.BIT, which Sqoop by default maps to Boolean.
Solution: A more clean solution is to force MySQL JDBC Connector to stop converting TINYINT(1) to java.sql.Types.BIT by adding tinyInt1isBit=false into your JDBC path (to create something like jdbc:mysql://localhost/test?tinyInt1isBit=false). Another solution would be to explicitly override the column mapping