CommonPartitioner.java 483 Bytes
Newer Older
wang-jinfeng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package mobvista.dmp.common;

import org.apache.hadoop.io.MD5Hash;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * author: houying
 * date  : 16-10-24
 * desc  :
 */
public class CommonPartitioner extends Partitioner<Text, Text> {
    @Override
    public int getPartition(Text text, Text text2, int numPartitions) {
        return ((MD5Hash.digest(text.toString()).quarterDigest() % numPartitions) + numPartitions) % numPartitions;
    }
}