sqoop db2 java.io.CharConversionException

本來用sqoop從db2的抽數腳本突然提示錯誤,以下java

16/11/09 15:37:53 INFO mapreduce.Job: Task Id : attempt_1472462720075_14348_m_000004_0, Status : FAILED
Error: java.io.IOException: SQLException in nextKeyValue
    at org.apache.sqoop.mapreduce.db.DBRecordReader.nextKeyValue(DBRecordReader.java:266)
    at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.nextKeyValue(MapTask.java:553)
    at org.apache.hadoop.mapreduce.task.MapContextImpl.nextKeyValue(MapContextImpl.java:80)
    at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.nextKeyValue(WrappedMapper.java:91)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
    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:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
Caused by: com.ibm.db2.jcc.am.SqlException: [jcc][t4][1065][12306][4.16.53] 捕獲到 java.io.CharConversionException。有關詳細信息,請參閱相鏈接的 Throwable。 ERRORCODE=-4220, SQLSTATE=null
    at com.ibm.db2.jcc.am.fd.a(fd.java:723)
    at com.ibm.db2.jcc.am.fd.a(fd.java:60)
    at com.ibm.db2.jcc.am.fd.a(fd.java:112)
    at com.ibm.db2.jcc.am.jc.a(jc.java:2870)
    at com.ibm.db2.jcc.am.jc.p(jc.java:527)
    at com.ibm.db2.jcc.am.jc.N(jc.java:1563)
    at com.ibm.db2.jcc.am.ResultSet.getStringX(ResultSet.java:1153)
    at com.ibm.db2.jcc.am.ResultSet.getString(ResultSet.java:1128)
    at org.apache.sqoop.lib.JdbcWritableBridge.readString(JdbcWritableBridge.java:71)
    at com.cloudera.sqoop.lib.JdbcWritableBridge.readString(JdbcWritableBridge.java:61)
    at QueryResult.readFields(QueryResult.java:210)
    at org.apache.sqoop.mapreduce.db.DBRecordReader.nextKeyValue(DBRecordReader.java:246)
    ... 12 more
Caused by: java.nio.charset.MalformedInputException: Input length = 67277
    at com.ibm.db2.jcc.am.r.a(r.java:19)
    at com.ibm.db2.jcc.am.jc.a(jc.java:2862)
    ... 20 more
Caused by: sun.io.MalformedInputException
    at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java:105)
    at com.ibm.db2.jcc.am.r.a(r.java:16)
    ... 21 moreapache

大概的緣由以下:app

When an application uses the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver) and is connected to a database with code set UTF-8 (code page 1208), it throws an
SqlException with message including "Caught java.io.CharConversionException" and ERRORCODE=-4220 if the data in a character column that it queries contains a sequence of bytes that is not a valid UTF-8 string.oop

解決以下:ui

下載對應版本的最新jdbc驅動包code

http://www-01.ibm.com/support/docview.wss?uid=swg21363866orm

可在程序中添加xml

System.setProperty("db2.jcc.charsetDecoderEncoder", "3");hadoop

get

java -Ddb2.jcc.charsetDecoderEncoder=3 MyApp

由於當前的做業使用的mr來運行,因此在mapred-site.xml中作以下修改便可:

<property>
<name>mapreduce.map.java.opts</name>
<value>-Xmx1024m -Ddb2.jcc.charsetDecoderEncoder=3</value>
</property>

修改後無需重啓集羣

相關文章
相關標籤/搜索