我计划在Hadoop0.20.2中的TeraSort类的映射器中插入一些代码。但是,在查看源代码后,我找不到实现mapper的部分。通常,我们会看到一个名为job.setMapperClass()的方法,它表示映射器类。然而,对于TeraSort,我只能看到像setInputformat,setOutputFormat这样的东西。我找不到mapper和reduce方法的调用位置?有没有人能就此给点提示?谢谢,源代码是这样的,
public int run(String[] args) throws Exception {
LOG.info("starting");
JobConf job = (JobConf) getConf();
Path inputDir = new Path(args[0]);
inputDir = inputDir.makeQualified(inputDir.getFileSystem(job));
Path partitionFile = new Path(inputDir, TeraInputFormat.PARTITION_FILENAME);
URI partitionUri = new URI(partitionFile.toString() +
"#" + TeraInputFormat.PARTITION_FILENAME);
TeraInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.setJobName("TeraSort");
job.setJarByClass(TeraSort.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setInputFormat(TeraInputFormat.class);
job.setOutputFormat(TeraOutputFormat.class);
job.setPartitionerClass(TotalOrderPartitioner.class);
TeraInputFormat.writePartitionFile(job, partitionFile);
DistributedCache.addCacheFile(partitionUri, job);
DistributedCache.createSymlink(job);
job.setInt("dfs.replication", 1);
// TeraOutputFormat.setFinalSync(job, true);
job.setNumReduceTasks(0);
JobClient.runJob(job);
LOG.info("done");
return 0;
}对于其他类,比如TeraValidate,我们可以找到如下代码:
job.setMapperClass(ValidateMapper.class);
job.setReducerClass(ValidateReducer.class);对于TeraSort,我看不到这样的方法。
谢谢,
发布于 2011-07-04 13:32:16
为什么排序需要为它设置Mapper和Reducer类?
默认值为标准Mapper (以前的身份映射器)和标准Reducer。这些是您通常继承的类。
您基本上可以说,您只是从输入发出所有内容,并让Hadoop自己进行排序。因此,排序是“默认”的。
发布于 2013-06-28 01:03:30
Thomas的回答是正确的,即映射器和减法器是相同的,因为混洗数据在应用reduce函数之前是排序的。terasort的特殊之处在于它的自定义分区程序(不是默认的散列函数)。你应该从这里阅读更多关于它的Hadoop's implementation for Terasort。它写道
TeraSort是标准的<= / reduce排序,但自定义分区程序除外,该程序使用定义每个reduce的键范围的N Sample1采样键的排序列表。尤其是,将所有这样的键发送到reduce i。这可以保证reduce i的输出都小于reduce i+1的输出。
https://stackoverflow.com/questions/6565255
复制相似问题