大数据全系列 教程
1869个小节阅读:467.5k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
自定义分区类如何定义:
xxxxxxxxxx
//自定义分区类的key,value的类型,要分别对应Mapper输出的key和value的类型
//自定义的分区列一定要继承Partitioner类,并覆写getPartition方法
//分区的原则:避免数据倾斜的出现
public class WCPartitioner extends Partitioner<Text, IntWritable> {
//abcdefghi jklmnopqr stuvwzyz 其他的
@Override
public int getPartition(Text key, IntWritable value, int numPartitions) {
//key转换为字符串
String word = key.toString();
char ch = word.charAt(0);
if(ch>='a'&&ch<='i'){
return 0;
}else if(ch>='j'&&ch<='r'){
return 1;
}else if(ch>='s'&&ch<='z'){
return 2;
}else{
return 3;
}
}
}