hadoop - 如果在 Hadoop Map Reduce 中定义了自定义分区程序,默认哈希分区程序是否仍然有效?

标签 hadoop mapreduce partitioner

由于我是 hadoop 的新手,我尝试了 http://www.tutorialspoint.com/map_reduce/map_reduce_partitioner.htm 中的示例代码我发现该程序根据年龄组使用了 3 个不同的分区,并且还使用了 3 个 reducer ,这是预期的。但是在 reducer 代码中(这里的性别是男/女的关键)我仍然得到,我假设这个值列表创建是由散列分区程序完成的。但是正如我定义的 getPartitions() ,谁来创建这个列表?

最佳答案

在上面的示例代码中,我们在运行方法中有以下驱动程序代码--

  Configuration conf = getConf();

  Job job = new Job(conf, "topsal");
  job.setJarByClass(PartitionerExample.class);

  FileInputFormat.setInputPaths(job, new Path(arg[0]));
  FileOutputFormat.setOutputPath(job,new Path(arg[1]));

  job.setMapperClass(MapClass.class);

  job.setMapOutputKeyClass(Text.class);
  job.setMapOutputValueClass(Text.class);

  //set partitioner statement

  job.setPartitionerClass(CaderPartitioner.class);
  job.setReducerClass(ReduceClass.class);
  job.setNumReduceTasks(3);
  job.setInputFormatClass(TextInputFormat.class);

  job.setOutputFormatClass(TextOutputFormat.class);
  job.setOutputKeyClass(Text.class);
  job.setOutputValueClass(Text.class);

  System.exit(job.waitForCompletion(true)? 0 : 1);
  return 0;

在这里你可以看到它设置了 CaderPartitioner 类作为上面 MR 的分区器。根据 Map Reduce 规范,如果我们的程序没有设置任何自定义分区器,那么只有在这种情况下,身份分区器才会出现。

所以在上面的场景中,CaderPartitioner 将发生并为上面的 MR 做分区。由于它有 3 个条件,它将把输入键分成 3 个不同的组,并将这些单独的组发送到不同的 reducer,reducer 将相应地发生。

希望这对您有所帮助。

关于hadoop - 如果在 Hadoop Map Reduce 中定义了自定义分区程序,默认哈希分区程序是否仍然有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33902885/

相关文章:

javascript - mongodb获取最古老的动物map/reduce

hadoop - AM如何为每个约简任务选择节点?

apache-spark - 为什么 sortBy 转换会触发 Spark 作业?

Hadoop 的操作顺序

索引 HDFS 序列文件

bash 在 case 语句中传递参数对

hadoop - 避免以编程方式使用创建的上下文启动 HiveThriftServer2

hadoop - 致命数据节点.DataNode : Exception in secureMain

java - Hadoop MapReduce 中数值数据集的分箱

hadoop - hadoop mapreduce分区程序未调用