2011-07-03 36 views
1

我打算在Hadoop 0.20.2中插入一些代码到TeraSort类的映射器中。但是,在查看源代码之后,我找不到映射器实现的片段。 通常,我们将看到一个名为job.setMapperClass()的方法,它指示映射器类。但是,对于TeraSort,我只能看到像setInputformat,setOutputFormat这样的东西。我无法找到调用mapper和reduce方法的地方? 任何人都可以提供一些关于此的提示吗?谢谢, 的源代码是这样的,为什么不为hadoop映射器/ reducer TeraSort

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这样的方法。

感谢,

回答

3

为什么要排序需要设置MapperReducer类呢?

默认值是标准Mapper(原身份映射程序)和标准Reducer。 这些是您通常继承的类。

基本上可以这样说,您只需输入所有内容并让Hadoop自行分类即可。所以排序是通过“默认”来工作的。

1

托马斯答案是正确的,即映射器和缩减器是身份,因为在应用您的缩减功能之前对已整理的数据进行排序。 terasort的特别之处在于它的自定义分区程序(它不是默认的哈希函数)。你应该从这里阅读更多关于Hadoop's implementation for Terasort。它声明

“TeraSort是一种标准的映射/缩减排序,除了使用定义每个缩减的键范围的N-1个采样键的排序列表的自定义分区,特别是所有键,例如[ i - 1] < = key < sample [i]被发送以减少i,这保证了reduce i的输出都小于reduce i + 1的输出。

相关问题