sqoop导出hive数据到mysql错误: Caused by: java.lang.RuntimeException: Can't parse input data

Sqoop Export数据到本地数据库时出现错误,命令如下:

sqoop export \
--connect 'jdbc:mysql://202.193.60.117/dataweb?useUnicode=true&characterEncoding=utf-8' \
--username root \
--password-file /user/hadoop/.password \
--table user_info_copy \
--export-dir /user/hadoop/user_info \
--input-fields-terminated-by "@"

错误日志如下:

Error: java.io.IOException: Can't export data, please check failed map task logs
    at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:112)
    at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:39)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
    at org.apache.sqoop.mapreduce.AutoProgressMapper.run(AutoProgressMapper.java:64)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:784)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
    at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
Caused by: java.lang.RuntimeException: Can't parse input data: '2,hello,456,0'
    at user_info_copy.__loadFromFields(user_info_copy.java:335)
    at user_info_copy.parse(user_info_copy.java:268)
    at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:83)
    ... 10 more
Caused by: java.lang.NumberFormatException: For input string: "2,hello,456,0"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:580)
    at java.lang.Integer.valueOf(Integer.java:766)
    at user_info_copy.__loadFromFields(user_info_copy.java:317)
    ... 12 more

  该错误的问题在于分隔符,因为您没有在配置单元表中指定分隔符,默认的配置单元分隔符是:

    '\ 001'字段终止

    '\ 002'的收藏品终止

    '\ 003'终止的地图密钥

    LINES终止于'\ n'

  所以要解决问题,就需要更改配置单元创建或sqoop作业中的分隔符来解决问题。在本问题中,我的表示在本地通过界面化管理工具创建的,分隔符换成“,”就能解决问题了,若是其他分隔符则对应改变就行;或者,使用以下语句重新创建表格并指定分隔符来解决。

ROW FORMAT DELIMITED FIELDS TERMINATED BY '分隔符'

 

以上就是博主为大家介绍的这一板块的主要内容,这都是博主自己的学习过程,希望能给大家带来一定的指导作用,有用的还望大家点个支持,如果对你没用也望包涵,有错误烦请指出。如有期待可关注博主以第一时间获取更新哦,谢谢!

posted @ 2018-06-21 21:07  子墨言良  阅读(6373)  评论(0编辑  收藏  举报