gpt4 book ai didi

java - 在hadoop(2.2.0)中使用新的api和工具接口(interface)

转载 作者:可可西里 更新时间:2023-11-01 16:15:38 25 4
gpt4 key购买 nike

(我敢肯定这个问题被问过几次了,但这是一个普遍的“模糊”问题,而且 hadoop api 本身和版本号非常困惑,我觉得我所有的谷歌搜索实际上都是无用的。所以我很抱歉,如果这是微不足道的)

我一直在尝试使用新的工具界面在 hadoop 中运行作业。我被告知作为一般规则,如果我使用新的 api,我应该避免使用 org.apache.hadoop.mapred 并仅使用“org.apache.hadoop.mapreduce”包中的类。

但是,在 tool 下的新 api 文档中查看代码示例时:

   public int run(String[] args) throws Exception {
// Configuration processed by ToolRunner
Configuration conf = getConf();

// Create a JobConf using the processed conf
JobConf job = new JobConf(conf, MyApp.class);

// Process custom command-line options
Path in = new Path(args[1]);
Path out = new Path(args[2]);

// Specify various job-specific parameters
job.setJobName("my-app");
job.setInputPath(in);
job.setOutputPath(out);
job.setMapperClass(MyMapper.class);
job.setReducerClass(MyReducer.class);

// Submit the job, then poll for progress until the job is complete
JobClient.runJob(job);
return 0;
}

他们似乎使用了旧 API 中的 JobConf 类,这也会为我生成错误。特别是我得到

The method setPartitionerClass(Class) in the type JobConf is not applicable for the arguments

在尝试设置我的 map、reduce、combiner 类时出现相应的其他错误。

使用新 api 中的“作业”类对我有用,但它的所有构造函数都被标记为已弃用。这样做的正确方法是什么?

当尝试使用 new api 中的 JobControl 类时,这变得更加丑陋,出于某种原因 wants to use the "Job" class来自 api。再次使用旧 api 中的作业类需要我也使用旧的 JobConf 类。我觉得这里有一些非常基本的东西我想念。

有人可以帮忙吗?

最佳答案

Using the 'Job' class from the new api works for me, but all it's constructors are marked deprecated. What is the correct way to do this?

在新 API 中获得工作的一种未弃用的方法是...

Job job = Job.getInstance(new Configuration());

This gets even more ugly when trying to use the JobControl class from the new api, which for some reason wants to use the "Job" class from the old api. and again using the job class from the old api requires me to use the old JobConf class as well.

在设计新的 API 时考虑到向后兼容性,这总是有点令人困惑。

JobControl.addJob(org.apache.hadoop.mapred.jobcontrol.Job)

将旧作业作为输入,

JobControl.addJob(new ControlledJob(org.apache.hadoop.mapreduce.Job, ...))

将新工作作为输入。

关于java - 在hadoop(2.2.0)中使用新的api和工具接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22024919/

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