gpt4 book ai didi

java - NoSuchMethodError : JobConf. getCredentials()

转载 作者:可可西里 更新时间:2023-11-01 08:47:26 26 4
gpt4 key购买 nike

我正在尝试将一个表从 MySQL 导入到 Hive。我测试过我正在与 MySQL 正确建立连接。现在所有的表数据也包装在 jar 中。然后在我得到这个 NoSuchMethodError 之后。我在 Windows 8 上运行 MySQL,Hadoop Hive 在 VirtualBox 中作为 Horton Sandbox 运行。

org.apache.hadoop.mapred.JobConf.getCredentials() 的 NoSuchMethodError

错误:

  INFO: Initializing JVM Metrics with processName=JobTracker, sessionId=
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.mapred.JobConf.getCredentials()Lorg/apache/hadoop/security/Credentials;
at org.apache.sqoop.mapreduce.db.DBConfiguration.setPassword(DBConfiguration.java:158)
at org.apache.sqoop.mapreduce.db.DBConfiguration.configureDB(DBConfiguration.java:144)
at org.apache.sqoop.mapreduce.DataDrivenImportJob.configureInputFormat(DataDrivenImportJob.java:171)
at org.apache.sqoop.mapreduce.ImportJobBase.runImport(ImportJobBase.java:231)
at org.apache.sqoop.manager.SqlManager.importTable(SqlManager.java:600)
at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:413)
at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:502)
at SqoopJavaInterface.importToHive(SqoopJavaInterface.java:66)
at SqoopJavaInterface.main(SqoopJavaInterface.java:32)

这是我的源代码:-

import java.io.IOException;    
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.sqoop.tool.ImportTool;

import com.cloudera.sqoop.SqoopOptions;

public class SqoopJavaInterface {
private static final String JOB_NAME = "Sqoop Hive Job";
private static final String MAPREDUCE_JOB = "Hive Map Reduce Job";
private static final String DBURL = "jdbc:mysql://localhost:3316/db";
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String USERNAME = "user";
private static final String PASSWORD = "password";
private static final String HADOOP_HOME = "/home/master/apps/hadoop-1.0.4";


private static final String JAR_OUTPUT_DIR = "/home/master/data";
private static final String HIVE_HOME = "/home/master/apps/hive-0.10.0";
private static final String HIVE_DIR = "/user/hive/warehouse/";
private static final String WAREHOUSE_DIR = "hdfs://localhost:9000/user/hive/warehouse/student";
private static final String SUCCESS = "SUCCESS !!!";
private static final String FAIL = "FAIL !!!";

/**
* @param table
* @throws IOException
*/
public static void main(String args[]) throws IOException{
importToHive("some_table");
}
public static void importToHive(String table) throws IOException {
System.out.println("SqoopOptions loading .....");
Configuration config = new Configuration();
// Hive connection parameters
config.addResource(new Path(HADOOP_HOME+"/conf/core-site.xml"));
config.addResource(new Path(HADOOP_HOME+"/conf/hdfs-site.xml"));
config.addResource(new Path(HIVE_HOME+"/conf/hive-site.xml"));
FileSystem dfs =FileSystem.get(config);
/* MySQL connection parameters */
SqoopOptions options = new SqoopOptions(config);
options.setConnectString(DBURL);
options.setTableName(table);
options.setDriverClassName(DRIVER);
options.setUsername(USERNAME);
options.setPassword(PASSWORD);
options.setHadoopMapRedHome(HADOOP_HOME);
options.setHiveHome(HIVE_HOME);
options.setHiveImport(true);
options.setHiveTableName(table);
options.setOverwriteHiveTable(true);
options.setFailIfHiveTableExists(false);
options.setFieldsTerminatedBy(',');
options.setOverwriteHiveTable(true);
options.setDirectMode(true);
options.setNumMappers(1); // No. of Mappers to be launched for the job
options.setWarehouseDir(WAREHOUSE_DIR);
options.setJobName(JOB_NAME);
options.setMapreduceJobName(MAPREDUCE_JOB);
options.setTableName(table);
options.setJarOutputDir(JAR_OUTPUT_DIR);
System.out.println("Import Tool running ....");
ImportTool it = new ImportTool();
int retVal = it.run(options);
if (retVal == 0) {
System.out.println(SUCCESS);
} else {
System.out.println(FAIL);
}
}
}

最佳答案

幸运的是,我自己找到了问题的答案。我必须在构建路径中包含一个 jar 文件 hadoop-0.20.2+737-core.jar而不是 hadoop-0.20.2-core.jar。看起来它是同一文件的修改版本,其中包含包含 getCredentials() 方法的 JobConf 类。

问题解决了,但我仍然对这两个版本感到困惑?有没有人知道实际的区别是什么?

关于java - NoSuchMethodError : JobConf. getCredentials(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24354054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com