欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

sqoop导出hive数据到mysql报错:Causedby:java.lang.RuntimeException:Can'tparseinputdata的解决办法

程序员文章站 2022-06-23 15:05:36
sqoop export数据到本地时出现错误,命令如下: sqoop export \ --connect 'jdbc:mysql://202.193.60.117/dataweb?u...

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 '分隔符'