运行 本地 hadoop map-reduce 未按预期对数据进行分区

Running a local hadoop map-reduce does not partition data as expected

我有一个 map-reduce 程序,它计算每十年从 google 个 ngram 中出现的 bigrams 的数量。
我的分区程序是:

public static class PartitionerClass extends Partitioner<Bigram, IntWritable> {
    public int getPartition(Bigram key, IntWritable value, int numPartitions) {
        String combined=key.getFirst().toString()+key.getSecond().toString()+key.getDecade().toString();
        return combined.hashCode()%numPartitions;
    }
}

我添加了一个断点,但程序没有执行那段代码。
我的主要:

Configuration conf = new Configuration();
Job job = new Job(conf, "first join");
job.setJarByClass(WordCount.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setPartitionerClass(PartitionerClass.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));    ///SHOULD BE DECIDED
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapOutputKeyClass(Bigram.class);
job.setMapOutputValueClass(IntWritable.class);
System.exit(job.waitForCompletion(true) ? 0 : 1);

代码未按预期运行,部分数据处理正确,部分数据处理不正确。
我真的不知道如何调试它。
有什么想法吗?

根据您提供的分区数,分区程序定义哪个键转到哪个分区。它的工作不是设置分区的数量,而是它们的内容。然后每个 reduce 任务处理一个分区,所以最后,分区数 = reduce 任务数 = 输出文件数(使用默认设置而不是 MultipleOutputs)。

为了设置分区数,您应该使用:

job.setNumReduceTasks(n);,其中 n 是您想要的数字。

有关如何设置此数字的说明(经验法则,没有什么严格要求),您可以阅读 this post