当前位置:网站首页>随着MapReduce job实现去加重,多种输出文件夹
随着MapReduce job实现去加重,多种输出文件夹
2022-07-06 10:19:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
总结以往的工作中遇到的一个问题。
背景: 操作和维护与scribe从apacheserver一再被推到日志记录,所以在这里ETL处理正在进行的重。有根据业务的输出类型是用于多文件夹一个需求。方便挂分区,使用回。 这两种需求都没有问题分开处理,一个mapreduce里完毕,须要一点技巧。
1、map输入数据,经过一系列处理。输出时:
if(ttype.equals("other")){
file = (result.toString().hashCode() & 0x7FFFFFFF)%400;
}else if(ttype.equals("client")){
file = (result.toString().hashCode() & 0x7FFFFFFF)%260;
}else{
file = (result.toString().hashCode()& 0x7FFFFFFF)%60;
}
tp = new TextPair(ttype+"_"+file, result.toString());
context.write(tp, valuet);valuet是空的,什么都没有。
我这里有三个类型。other,client,wap,分别代表日志来源平台。要按他们分文件夹输出。 result就是整条记录。
file得到的是终于输出文件名称,hash。位操作,取模是为了输出均衡。
map的输出结构<key,value> =(ttype+”_”+file,result.toString()) 这样做的目的是:保证同样的记录得到同样的key,同一时候还要保存类型。partition要按textPair的left,也就是这个key, 保证了后面要写到同一个输出文件的全部记录都到同一个reduce里去。一个reduce能够写多个输出文件。可是一个输出文件不能来自多个reduce,原因非常明了。 这种话大概400+260+60=720个输出文件,每一个文件数据量大概差点儿相同,job的reduce数我这里设置的240,这个数连同取模400,260,60都是依据我的数据量来定的,来尽量避免reduce的数据倾斜。 2、reduce方法去重:
public void reduce(TextPair key, Iterable<Text> values, Context context) throws IOException, InterruptedException
{
rcfileCols = getRcfileCols(key.getSecond().toString().split("\001"));
context.write(key.getFirst(), rcfileCols);
}不用迭代,对同样的key组。仅仅输出一次。注意这里job用到的比較器,一定不能是FirstComparator,而是整个textpair对的比較。(先比較left。再比較right) 我的程序里输出文件格式是rcfile。 3、多文件夹输出:
job.setOutputFormatClass(WapApacheMutiOutputFormat.class);
public class WapApacheMutiOutputFormat extends RCFileMultipleOutputFormat<Text, BytesRefArrayWritable> {
Random r = new Random();
protected String generateFileNameForKeyValue(Text key, BytesRefArrayWritable value,
Configuration conf) {
String typedir = key.toString().split("_")[0];
return typedir+"/"+key.toString();
}
}这里的RCFileMultipleOutputFormat是自己继承自FileOutputFormat 自己写的。主要实现了recordWriter。
终于输出去重的,分文件夹的数据文件。
理解的关键,主要是partition key设计。reduce原则。
版权声明:本文博客原创文章,博客,未经同意,不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117394.html原文链接:https://javaforall.cn
边栏推荐
- 重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
- Today in history: the mother of Google was born; Two Turing Award pioneers born on the same day
- 测试123
- The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
- 李書福為何要親自掛帥造手機?
- Video fusion cloud platform easycvr adds multi-level grouping, which can flexibly manage access devices
- Jerry's watch deletes the existing dial file [chapter]
- Transfer data to event object in wechat applet
- ASEMI整流桥DB207的导通时间与参数选择
- 容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)
猜你喜欢

Olivetin can safely run shell commands on Web pages (Part 1)

模板于泛型编程之declval

Declval of template in generic programming

递归的方式

传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复

Maixll dock camera usage

std::true_ Type and std:: false_ type

Compilation principle - top-down analysis and recursive descent analysis construction (notes)

【.NET CORE】 请求长度过长报错解决方案

Getting started with pytest ----- allow generate report
随机推荐
第三季百度网盘AI大赛盛夏来袭,寻找热爱AI的你!
ASEMI整流桥DB207的导通时间与参数选择
Codeforces Round #803 (Div. 2)
Principle and usage of extern
std::true_type和std::false_type
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
STM32 key state machine 2 - state simplification and long press function addition
C语言自动预订飞机票问题
李書福為何要親自掛帥造手機?
Cobra 快速入门 - 专为命令行程序而生
Top command details
Virtual machine VirtualBox and vagrant installation
The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
Will openeuler last long
2022 Summer Project Training (II)
IP, subnet mask, gateway, default gateway
使用block实现两个页面之间的传统价值观
从交互模型中蒸馏知识!中科大&美团提出VIRT,兼具双塔模型的效率和交互模型的性能,在文本匹配上实现性能和效率的平衡!...
I want to say more about this communication failure
Kivy tutorial: support Chinese in Kivy to build cross platform applications (tutorial includes source code)