Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partitioning! how does hadoop make it? Use a hash function? what is the default function?

Partitioning is the process of determining which reducer instance will receive which intermediate keys and values. Each mapper must determine for all of its output (key, value) pairs which reducer will receive them. It is necessary that for any key, regardless of which mapper instance generated it, the destination partition is the same Problem: How does hadoop make it? Use a hash function? what is the default function?

like image 269
cherri_zj Avatar asked Aug 27 '13 16:08

cherri_zj


People also ask

How does partition work in Hadoop?

Hadoop Partitioning specifies that all the values for each key are grouped together. It also makes sure that all the values of a single key go to the same reducer. This allows even distribution of the map output over the reducer.

Is the default partitioner in Hadoop?

The default partitioner in Hadoop is the HashPartitioner which has a method called getPartition . It takes key.

What is default partition in MapReduce and how can we override it?

Default MapReduce Partitioner The Default Hadoop partitioner in Hadoop MapReduce is Hash Partitioner which computes a hash value for the key and assigns the partition based on this result.

Is the default partitioner for partitioning key space?

10. _________ is the default Partitioner for partitioning key space. Explanation: The default partitioner in Hadoop is the HashPartitioner which has a method called getPartition to partition.


1 Answers

The default partitioner in Hadoop is the HashPartitioner which has a method called getPartition. It takes key.hashCode() & Integer.MAX_VALUE and finds the modulus using the number of reduce tasks.

For example, if there are 10 reduce tasks, getPartition will return values 0 through 9 for all keys.

Here is the code:

public class HashPartitioner<K, V> extends Partitioner<K, V> {
    public int getPartition(K key, V value, int numReduceTasks) {
        return (key.hashCode() & Integer.MAX_VALUE) % numReduceTasks;
    }
}

To create a custom partitioner, you would extend Partitioner, create a method getPartition, then set your partitioner in the driver code (job.setPartitionerClass(CustomPartitioner.class);). This is particularly helpful if doing secondary sort operations, for example.

like image 122
tommy_o Avatar answered Sep 28 '22 08:09

tommy_o