hadoop - 我们如何控制特定的键应该进入特定的 reducer ?

标签 hadoop mapreduce

我们如何控制特定的键应该进入特定的 reducer ?有人可以帮我解决这个问题吗?

最佳答案

partitioner是控制将哪些 key 发送到特定 reducer 的主要机制。

Partitioner controls the partitioning of the keys of the intermediate map-outputs. The key (or a subset of the key) is used to derive the partition, typically by a hash function. The total number of partitions is the same as the number of reduce tasks for the job. Hence this controls which of the m reduce tasks the intermediate key (and hence the record) is sent for reduction.

默认分区器是 HashPartitoner ,它使用 hashCode()键对象以确定将给定键发送到哪个归约。

在您的驱动程序中,您可以使用以下方法设置不同的分区程序:

job.setPartitionerClass(Class<? extends Partitioner> cls)

自定义分区器实现了 Partitioner<K2, V2>具有单一方法的接口(interface) getPartition(KEY key, VALUE value, int numPartitions)需要实现。

例如 HashPartitioner实现getPartition看起来像:

public int getPartition(K2 key, V2 value,int numReduceTasks) {
  return (key.hashCode() & Integer.MAX_VALUE) % numReduceTasks;
}

关于hadoop - 我们如何控制特定的键应该进入特定的 reducer ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38736118/

相关文章:

sql - hive 连接

hadoop - 如何在Ubuntu 12.04上构建Hadoop(1.0.4)libhfs

java - 错误 : java. lang.ClassNotFoundException : org. apache.mahout.common.RandomWrapper

java - Cloudera Quickstart VM illegalArguementException : Wrong FS: hdfs: expected: file:

java - org.apache.hive.jdbc.HiveStatement/org.apache.hadoop.hive.jdbc.HiveStatement 之间的区别

hadoop - 分析MapReduce作业

java - Hadoop项目启动时需要的JAR有哪些?

hadoop - hadoop显示 map 减少两次运行的百分比

java - java.lang.OutOfMemoryError:运行配置单元表扫描时,Java堆空间错误

java - Mongodb选择所有字段按一个字段分组并按另一个字段排序