sqoop从mysql导入数据到hive时tinyint字段自动变成Boolean解决方案

最近在做sqoop导出数据的时候,mysql中有的字段到hive中自动转换成boolean类型了.这个需要解决,不然数据对不上.
sqoop导入字段自动转换问题
查了查官方文档,官方文档里有说明,这里贴一下文档.
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 for the datatype TINYINT(1) column. For example, if the column name is foo, then pass the following option to Sqoop during import: --map-column-hive foo=tinyint. In the case of non-Hive imports to HDFS, use --map-column-java foo=integer.
官方文档里也给出了解决方法,有两个解决方法

  1. 在jdbc链接后面加上:tinyInt1isBit=false. 例: --connecttion jdbc:mysql://localhost/test?tinyInt1isBit=false
  2. 显式覆盖数据类型TINYINT(1)列的列映射. 例: 如果列名为foo,则在导入期间将以下选项传递给Sqoop: – map-column-hive foo = tinyint。在非Hive导入HDFS的情况下,使用–map-column-java foo = integer

参考: 官方文档

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值