当前位置:网站首页>随着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
边栏推荐
- ASEMI整流桥DB207的导通时间与参数选择
- Pytest learning ----- pytest operation mode and pre post packaging of interface automation testing
- MSF横向之MSF端口转发+路由表+SOCKS5+proxychains
- QT中Model-View-Delegate委托代理机制用法介绍
- The difference between parallelism and concurrency
- The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
- 2019阿里集群数据集使用总结
- MarkDown语法——更好地写博客
- 首先看K一个难看的数字
- Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
猜你喜欢
![[Android] kotlin code writing standardization document](/img/d5/53d6a75e87af15799bf7e5d6eb92a5.png)
[Android] kotlin code writing standardization document

Recommend easy-to-use backstage management scaffolding, everyone open source

The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!

IP, subnet mask, gateway, default gateway

Transport layer congestion control - slow start and congestion avoidance, fast retransmission, fast recovery

std::true_type和std::false_type

Open source and safe "song of ice and fire"

FMT开源自驾仪 | FMT中间件:一种高实时的分布式日志模块Mlog

当保存参数使用结构体时必备的开发技巧方式

【.NET CORE】 请求长度过长报错解决方案
随机推荐
30 分钟看懂 PCA 主成分分析
2019 Alibaba cluster dataset Usage Summary
STM32 key state machine 2 - state simplification and long press function addition
This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
C语言指针*p++、*(p++)、*++p、*(++p)、(*p)++、++(*p)对比实例
2022 Summer Project Training (III)
Jerry is the custom background specified by the currently used dial enable [chapter]
Maixll-Dock 摄像头使用
[Android] kotlin code writing standardization document
Declval of template in generic programming
Why does wechat use SQLite to save chat records?
【.NET CORE】 请求长度过长报错解决方案
1700C - Helping the Nature
Codeforces Round #803 (Div. 2)
STM32+ENC28J60+UIP协议栈实现WEB服务器示例
2022 Summer Project Training (I)
MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
解读云原生技术
TCP packet sticking problem
Fleet tutorial 13 basic introduction to listview's most commonly used scroll controls (tutorial includes source code)