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

标签 java hadoop mapreduce

我有一个map-reduce程序,可以计算每十年Google ngrams中出现的双字母组的数量。
我的分区器是:

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

代码未按预期运行,某些数据已正确处理,而某些数据未正确处理。
我真的不知道该如何调试。
有任何想法吗?

最佳答案

根据给定的分区数量,分区程序定义将哪个键分配给哪个分区。它的工作不是设置分区的数量,而是设置其内容。然后,每个缩减任务将处理一个分区,因此最后,分区数=缩减任务数=输出文件数(正在使用默认设置,而不是MultipleOutputs)。

为了设置分区数,您应该使用:
job.setNumReduceTasks(n);,其中n是您想要的数字。

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

关于java - 运行本地hadoop map-reduce不会按预期对数据进行分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42540627/

相关文章:

java - 如何重命名我的包裹? IntelliJ

hadoop - 使用 webhdfs 的 GETFACL 中未显示掩码值

java - 在 HBase MapReduce 任务中加载 native 共享库

java - Spring Boot针对不同的h2测试使用不同的data.sql文件

java - 为什么需要通过 getErrorStream() 来运行进程?

java - 使用 Jackson 进行反序列化

hadoop - 更新 CDH (5.0.0 -> 5.0.2) 后无法启动 impala

hadoop - 仅在 "-Dorg.apache.sqoop.splitter.allow_text_splitter=true"属性作为参数传递的情况下才允许为文本索引列生成拆分

hadoop - 使用 Hadoop MapReduce 按月份和 IP 对日志条目进行分组

java - Hadoop映射器构造函数,何时以及如何?