2017-10-05 61 views
0

我想從Mysql數據導入到HDFSSqoop2Sqoop2未能從MySQL導入與HDFS「產生的原因:java.lang.ClassCastException:java.math.BigInteger中不能轉換爲java.lang.Long中的」

我的表看起來像

CREATE TABLE `campaign` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 
    `name` varchar(128) NOT NULL, 
    PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 

我創建2個鏈接

sqoop:000> show link 
+----+-------+--------------+------------------------+---------+ 
| Id | Name | Connector Id |  Connector Name  | Enabled | 
+----+-------+--------------+------------------------+---------+ 
| 2 | hdfs | 3   | hdfs-connector   | true | 
| 7 | mysql | 1   | generic-jdbc-connector | true | 
+----+-------+--------------+------------------------+---------+ 

我已經創建工作與

Table SQL statement: SELECT id, name FROM campaign WHERE ${CONDITIONS} 

而且我已經試過這條SQL語句 - 它也沒有工作

Table SQL statement: SELECT cast(id as UNSIGNED INTEGER) id, name FROM campaign WHERE ${CONDITIONS} 

我的工作是這樣的:

sqoop:000> show job 
+----+-----------------+----------------+--------------+---------+ 
| Id |  Name  | From Connector | To Connector | Enabled | 
+----+-----------------+----------------+--------------+---------+ 
| 4 | campaign_import | 1    | 3   | true | 
+----+-----------------+----------------+--------------+---------+ 

我已經成功地運行該作業

sqoop:000> start job -j 4 

然後我在mappers上發現錯誤

Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long at

錯誤的全文貌似

Error: org.apache.sqoop.common.SqoopException: MAPRED_EXEC_0017:Error occurs during extractor run at org.apache.sqoop.job.mr.SqoopMapper.run(SqoopMapper.java:99) at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341) at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164) 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:1917) at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158) Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long at org.apache.sqoop.connector.common.SqoopIDFUtils.toCSVFixedPoint(SqoopIDFUtils.java:133) at org.apache.sqoop.connector.common.SqoopIDFUtils.toCSV(SqoopIDFUtils.java:588) at org.apache.sqoop.connector.idf.CSVIntermediateDataFormat.toCSV(CSVIntermediateDataFormat.java:116) at org.apache.sqoop.connector.idf.CSVIntermediateDataFormat.setObjectData(CSVIntermediateDataFormat.java:87) at org.apache.sqoop.job.mr.SqoopMapper$SqoopMapDataWriter.writeArrayRecord(SqoopMapper.java:125) at org.apache.sqoop.connector.jdbc.GenericJdbcExtractor.extract(GenericJdbcExtractor.java:96) at org.apache.sqoop.connector.jdbc.GenericJdbcExtractor.extract(GenericJdbcExtractor.java:38) at org.apache.sqoop.job.mr.SqoopMapper.run(SqoopMapper.java:95) ... 7 more 

它看起來像id類型(BIGINT)爲campaign表的問題,但我不知道如何解決它不改變此字段類型: )

也許,有人有什麼想法?

回答

0

這對我的作品時,我已經改變了表的SQL語句

SELECT cast(id as SIGNED INTEGER) id, name FROM campaign WHERE ${CONDITIONS} 

我更仔細地看了看,只見那

1)隨着表的SQL語句:SELECT id, name FROM campaign WHERE ${CONDITIONS}我得了錯誤:

Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

2)隨着表的SQL語句:SELECT cast(id as UNSIGNED INTEGER) id, name FROM campaign WHERE ${CONDITIONS}我得了錯誤:

Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

所以問題是與鑄造,我需要投BIGINTSIGNED INTEGER

相關問題