当前位置:网站首页>随着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
边栏推荐
- 带你穿越古罗马,元宇宙巴士来啦 #Invisible Cities
- The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
- This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
- Virtual machine VirtualBox and vagrant installation
- 2019阿里集群数据集使用总结
- 第三季百度网盘AI大赛盛夏来袭,寻找热爱AI的你!
- 重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
- Redis的五种数据结构
- 【Swoole系列2.1】先把Swoole跑起来
- OpenEuler 会长久吗
猜你喜欢

Distill knowledge from the interaction model! China University of science and Technology & meituan proposed virt, which combines the efficiency of the two tower model and the performance of the intera

Recursive way

带你穿越古罗马,元宇宙巴士来啦 #Invisible Cities
![Jerry's updated equipment resource document [chapter]](/img/6c/17bd69b34c7b1bae32604977f6bc48.jpg)
Jerry's updated equipment resource document [chapter]

2019 Alibaba cluster dataset Usage Summary

递归的方式

Getting started with pytest ----- allow generate report

F200——搭载基于模型设计的国产开源飞控系统无人机

1700C - Helping the Nature

On time and parameter selection of asemi rectifier bridge db207
随机推荐
Brief description of SQL optimization problems
重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
STM32按键状态机2——状态简化与增加长按功能
Distiller les connaissances du modèle interactif! L'Université de technologie de Chine & meituan propose Virt, qui a à la fois l'efficacité du modèle à deux tours et la performance du modèle interacti
The latest financial report release + tmall 618 double top, Nike energy leads the next 50 years
2022 Summer Project Training (I)
TOP命令详解
Implementation of queue
Recommend easy-to-use backstage management scaffolding, everyone open source
d绑定函数
ASEMI整流桥DB207的导通时间与参数选择
Jerry's setting currently uses the dial. Switch the dial through this function [chapter]
[Android] kotlin code writing standardization document
[.Net core] solution to error reporting due to too long request length
Why should Li Shufu personally take charge of building mobile phones?
Jerry's access to additional information on the dial [article]
Jerry's watch reads the file through the file name [chapter]
Is it meaningful for 8-bit MCU to run RTOS?
MSF横向之MSF端口转发+路由表+SOCKS5+proxychains