我想将数据从Mysql
导入到HDFS
Sqoop2
我的表格似乎是
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
然后我在我的映射器上发现错误
引起:java.lang.ClassCastException:java.math.BigInteger不能 在
转换为java.lang.Long
错误的全文如下
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 :(得分:0)
当我将Table SQL语句更改为
时,它对我有用SELECT cast(id as SIGNED INTEGER) id, name FROM campaign WHERE ${CONDITIONS}
我仔细观察并看到了
1)使用表SQL语句:SELECT id, name FROM campaign WHERE ${CONDITIONS}
我发现了错误:
引起:java.lang.ClassCastException:java.math.BigInteger不能 被强制转换为java.lang.Long
2)使用表SQL语句:SELECT cast(id as UNSIGNED INTEGER) id, name FROM campaign WHERE ${CONDITIONS}
我发现了错误:
引起:java.lang.ClassCastException:java.lang.Long无法强制转换 到java.lang.Integer
问题在于投射,我需要将BIGINT
投射到SIGNED INTEGER