【问题标题】:total order partitioner in hadoophadoop中的全序分区器
【发布时间】:2013-10-21 16:07:29
【问题描述】:

我对totalorderpartitioner 的概念完全陌生,我已经应用了这个概念,但我没有成功地产生全局排序。 这是我的输入记录

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);

但是记录没有得到排序。这是我的输出

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

我不知道我哪里出错了。谁能帮我解决这个问题?谁能告诉我输入采样是如何工作的。提前谢谢

【问题讨论】:

    标签: hadoop mapreduce mapper reducers


    【解决方案1】:

    Mapreduce 对 key 进行排序,因为您是在 nullwritable 上排序,所以您根本没有进行排序:

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

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

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

    你能试一试,让我们知道它是否成功吗?

    第二点:使用 IntWritable 而不是 Text 否则排序将按字典顺序排列!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      • 2013-08-23
      • 2021-10-14
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      相关资源
      最近更新 更多