alexander.polomodov
alexander.polomodov

Reputation: 5534

Sqoop2 failed import from mysql to hdfs with "Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long"

I want to import data from Mysql to HDFS with Sqoop2

My table looks like

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

I've created 2 links

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

I've created job with

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

Also I've tried this sql statement - it also didn't work

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

My job looks like:

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

I've successfully run this job

sqoop:000> start job -j 4

And then I've catched error on my mappers

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

Full text of error looks like

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

It looks like problem of id type (bigint) into campaign table, but I don't know how to fix it without changing this field type:)

Maybe, somebody has any idea?

Upvotes: 0

Views: 1091

Answers (1)

alexander.polomodov
alexander.polomodov

Reputation: 5534

It works for me when I've changed Table SQL statement to

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

I looked more closely and saw that

1) With Table SQL statement: SELECT id, name FROM campaign WHERE ${CONDITIONS} I've caught error:

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

2) With Table SQL statement: SELECT cast(id as UNSIGNED INTEGER) id, name FROM campaign WHERE ${CONDITIONS} I've caught error:

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

So problem was with casting and I need to cast BIGINT to SIGNED INTEGER

Upvotes: 0

Related Questions