String url = "http://localhost:12000/sqoop/";
SqoopClient client = new SqoopClient(url);
//Creating dummy job object
MJob job = client.createJob("fromLinkName", "toLinkName");
job.setName("Vampire");
job.setCreationUser("Buffy");
// set the "FROM" link job config values
MFromConfig fromJobConfig = job.getFromJobConfig();
fromJobConfig.getStringInput("fromJobConfig.schemaName").setValue("sqoop");
fromJobConfig.getStringInput("fromJobConfig.tableName").setValue("sqoop");
fromJobConfig.getStringInput("fromJobConfig.partitionColumn").setValue("id");
// set the "TO" link job config values
MToConfig toJobConfig = job.getToJobConfig();
toJobConfig.getStringInput("toJobConfig.outputDirectory").setValue("/usr/tmp");
// set the driver config values
MDriverConfig driverConfig = job.getDriverConfig();
driverConfig.getIntegerInput("throttlingConfig.numExtractors").setValue(3);
以上是官方文档中的job创建的代码,但运行是会抛出以下错误
Error: org.apache.sqoop.common.SqoopException:MAPRED_EXEC_0018:Error occurs during loader run at
org.apache.sqoop.job.mr.SqoopOutputFormatLoadExecutor$Cons
umerThread.run(SqoopOutputFormatLoadExecutor.java:292) at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at
java.util.concurrent.FutureTask.run(FutureTask.java:266) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Thread
PoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by:
org.apache.sqoop.common.SqoopException: CORE_0000:An
unknown error has occurred at
org.apache.sqoop.utils.ClassUtils.executeWithClassLoader(
ClassUtils.java:286) at
org.apache.sqoop.job.mr.SqoopOutputFormatLoadExecutor$Con
sumerThread.run(SqoopOutputFormatLoadExecutor.java:259)
... 5 more Caused by: java.lang.NullPointerException at
org.apache.sqoop.connector.hdfs.HdfsLoader.getExtension(H
dfsLoader.java:161) at
org.apache.sqoop.connector.hdfs.HdfsLoader.access$100(Hdf
sLoader.java:45) at
org.apache.sqoop.connector.hdfs.HdfsLoader$1.run(HdfsLoad
er.java:86) at
org.apache.sqoop.connector.hdfs.HdfsLoader$1.run(HdfsLoad
er.java:60) at
java.security.AccessController.doPrivileged(Native
Method) at
javax.security.auth.Subject.doAs(Subject.java:422) at
org.apache.hadoop.security.UserGroupInformation.doAs(User
GroupInformation.java:1698) at
org.apache.sqoop.connector.hdfs.HdfsLoader.load(HdfsLoade
r.java:60) at
org.apache.sqoop.connector.hdfs.HdfsLoader.load(HdfsLoade
r.java:45) at
org.apache.sqoop.job.mr.SqoopOutputFormatLoadExecutor$Con
sumerThread$1.call(SqoopOutputFormatLoadExecutor.java:279) at
org.apache.sqoop.job.mr.SqoopOutputFormatLoadExecutor$Con
sumerThread$1.call(SqoopOutputFormatLoadExecutor.java:260
) at
org.apache.sqoop.utils.ClassUtils.executeWithClassLoader(
ClassUtils.java:281) ... 6 more
原因是没有指定结果输出类型
应在
// set the “TO” link job config values下指定输出格式
toJobConfig.getInput("toJobConfig.outputFormat").setValue("TEXT_FILE");