gpt4 book ai didi

hadoop - 在哪里调用 Map 方法?

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

我正在寻找 hadoop 中 map 方法的内部工作。在哪里调用 map 方法?它是调用 map 方法的运行方法吗?

最佳答案

我引用了 Apache 文档中的示例代码 page进一步回答您的问题。

Driver 类,其中有用于字数统计示例的 main 方法,定义如下。

public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}

现在来自 grepcode 网站 Job类,回溯当你在 Job 类中使用 waitForCompletion 方法时发生了什么。

/**
* Submit the job to the cluster and wait for it to finish.
* @param verbose print the progress to the user
* @return true if the job succeeded
* @throws IOException thrown if the communication with the
* <code>JobTracker</code> is lost
*/
public boolean waitForCompletion(boolean verbose
) throws IOException, InterruptedException,
ClassNotFoundException {
if (state == JobState.DEFINE) {
submit();
}
if (verbose) {
jobClient.monitorAndPrintJob(conf, info);
} else {
info.waitForCompletion();
}
return isSuccessful();
}

}

现在检查 Job 类中的 submit() 方法代码。

/**
* Submit the job to the cluster and return immediately.
* @throws IOException
*/
public void submit() throws IOException, InterruptedException,
ClassNotFoundException {
ensureState(JobState.DEFINE);
setUseNewAPI();

// Connect to the JobTracker and submit the job
connect();
info = jobClient.submitJobInternal(conf);
super.setJobID(info.getID());
state = JobState.RUNNING;
}

现在来自 JobClient 的 grepcode 站点类:

检查源代码

公开

RunningJob submitJobInternal(final JobConf job
) throws FileNotFoundException,
ClassNotFoundException,
InterruptedException,
IOException

请参阅下面的帖子了解内部结构以及 grepcode。

What is the difference between JobClient.java and JobSubmitter.java in hadoop2?

关于hadoop - 在哪里调用 Map 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37189224/

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