2013-10-14 50 views
1

我完全陌生于totalorderpartitioner的概念,我已经应用了这个概念,但是我没有成功地生成全局排序。 这是我的输入记录 hadoop中的全部命令分区器

676576 
7489768576 
689576857867857 
685768578678578675 
765897685789675879679587 
1 
5 
6 
7 
8 
9 
0 
2 
3 
5 
6 
9 

这是我的映射

public void map(LongWritable key, Text value, 
      OutputCollector<NullWritable, Text> outputCollector, Reporter reporter) throws IOException { 
     // TODO Auto-generated method stub 
     outputCollector.collect(NullWritable.get(),value); 

    } 

这是我减速

public void reduce(NullWritable key, Iterator<Text> values, 
      OutputCollector<NullWritable, Text> outputCollector, Reporter reporter) throws IOException { 
     // TODO Auto-generated method stub 
     while (values.hasNext()) { 
      Text text = (Text) values.next(); 
      outputCollector.collect(key,text); 

     } 

    } 

这是我的工作相关的代码

JobConf jobConf = new JobConf(); 
jobConf.setMapperClass(TotalOrderMapper.class); 
jobConf.setReducerClass(TotalOrderReducer.class); 
jobConf.setMapOutputKeyClass(NullWritable.class); 
jobConf.setMapOutputValueClass(Text.class); 
jobConf.setOutputKeyClass(NullWritable.class); 
jobConf.setOutputValueClass(Text.class); 
jobConf.setPartitionerClass(TotalOrderPartitioner.class); 
jobConf.setInputFormat(TextInputFormat.class); 
jobConf.setOutputFormat(TextOutputFormat.class); 
FileInputFormat.addInputPath(jobConf, new Path("hdfs://localhost:9000/totalorderset.txt")); 
FileOutputFormat.setOutputPath(jobConf, new Path("hdfs://localhost:9000//sortedRecords5.txt")); 
Path pa = new Path("hdfs://localhost:9000//partitionfile","_partitions.lst"); 
TotalOrderPartitioner.setPartitionFile(jobConf, 
     pa); 
InputSampler.writePartitionFile(jobConf, 
     new InputSampler.RandomSampler(1,1)); 
JobClient.runJob(jobConf); 

但记录没有得到排序。这是我的outp UT

676576 
7489768576 
689576857867857 
685768578678578675 
765897685789675879679587 
1 
5 
6 
7 
8 
9 
0 
2 
3 
5 
6 
9 

我不知道我要多多wrong.could谁能帮助我理清问题吗?和任何人都可以告诉我inputsampling是怎么工作的here.thanks提前

回答

2

MapReduce的各种关键的,因为你正在排序的可执行文件你根本没有排序:

outputCollector.collect(NullWritable.get(),value); 

你的地图输出键应该是你的输入值!

outputCollector.collect(value, NullWritable.get()); 

你可以试试看,让我们知道它是否有诀窍?

第二个备注:使用IntWritable而不是文本,否则排序将按字典顺序!