针对微信的一篇推送附有的数据链接进行MapReduce统计
原推送引用:https://mp.weixin.qq.com/s/3qQqN6qzQ3a8_Au2qfZnVg
版权归原作者所有,如有侵权请及时联系本人,见谅!
原文采用Excel进行统计数据,这里采用刚学习的工具进行练习。
import java.io.IOException; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; /**
* https://mp.weixin.qq.com/s/3qQqN6qzQ3a8_Au2qfZnVg
* 针对[新兴生态系统:Python和R语言,谁更适用于大数据Spark/Hadoop和深度学习?]
* 的全球数据进行一系列统计
*/
public class wechat extends Configured implements Tool { /**
* Map方法
*/
private static class ModuleMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
private static final IntWritable mapOutputValue = new IntWritable(1) ;
private Text mapOutputKey = new Text() ;
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException { String input = value.toString();
if(input.split(",").length<16) {
return;
}
String[] arrStr = input.split(",");
//Python-大数据计数器输出
if("1".equals(arrStr[2])&&"1".equals(arrStr[14])) {
context.getCounter("WECHAT_MAPPER_COUNTERS", "Python_BigData").increment(1L);
}
//Python-Deep计数器输出
if("1".equals(arrStr[2])&&"1".equals(arrStr[13])) {
context.getCounter("WECHAT_MAPPER_COUNTERS", "Python_Deep-Learning").increment(1L);
}
//R-大数据计数器输出
if("1".equals(arrStr[3])&&"1".equals(arrStr[14])) {
context.getCounter("WECHAT_MAPPER_COUNTERS", "R_BigData").increment(1L);
}
//R-深度计数器输出
if("1".equals(arrStr[3])&&"1".equals(arrStr[13])) {
context.getCounter("WECHAT_MAPPER_COUNTERS", "R_Deep-Learning").increment(1L);
} arrStr = input.split(",")[16].split(";");
//遍历
for(String tool: arrStr){
// 设置key
mapOutputKey.set(tool);
// 输出
context.write(mapOutputKey, mapOutputValue) ;
}
}
} /**
* Reduce聚合结果
*/
private static class ModuleReducer extends Reducer<Text, IntWritable, Text, IntWritable>{
private IntWritable outputValue = new IntWritable() ;
@Override
protected void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException { // 定义临时变量,用于累加
int sum = 0 ; // 遍历
for(IntWritable value: values){
sum += value.get() ;
} if(sum < 500){
// 定义500以上的筛选
return ;
}
// 设置
outputValue.set(sum) ;
// 输出
context.write(key, outputValue) ; }
} /**
* 驱动创建Job并提交运行 返回状态码
*/ public int run(String[] args) throws Exception {
// 创建一个Job
Job job = Job.getInstance(
this.getConf() , wechat.class.getSimpleName()
) ;
// 设置job运行的class
job.setJarByClass(wechat.class); // 设置Job
// 1. 设置 input,从哪里读取数据
Path inputPath = new Path(args[0]) ;
FileInputFormat.addInputPath(job, inputPath); // 2. 设置 mapper类
job.setMapperClass(ModuleMapper.class);
// 设置map 输出的key和value的数据类型
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class); // 3. 设置 reducer 类
job.setReducerClass(ModuleReducer.class);
// 设置 reducer 输出的key和value的数据类型
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
// 设置ReduceTask个数
// job.setNumReduceTasks(2); // 4. 设置 处理结果保存的路径
Path outputPath = new Path(args[1]) ;
FileOutputFormat.setOutputPath(job, outputPath); // 提交job运行
boolean isSuccess = job.waitForCompletion(true) ; // 返回状态
return isSuccess ? 0 : 1;
} /**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
if(2 > args.length){
System.out.println("Usage: " + wechat.class.getSimpleName() +" <in> <out>");
return ;
} // 读取HADOOP中配置文件, core-*.xml hdfs-*.xml yarn-*.xml mapred-*.xml
Configuration conf = new Configuration() ; // 运行Job
int status = ToolRunner.run(conf, new wechat(), args) ; // exit program
System.exit(status);
} }
针对微信的一篇推送附有的数据链接进行MapReduce统计的更多相关文章
- 微信小程序--消息推送配置Token令牌错误校验失败如何解决
微信开放第三方API接口, 申请地址: https://mp.weixin.qq.com/advanced/advanced?action=interface&t=advanced/inter ...
- php 微信客服信息推送失败 微信重复推送客服消息 40001 45047
/*** * 微信客服发送信息 * 微信客服信息推送失败 微信重复推送客服消息 40001 45047 * 递归提交到微信 直到提交成功 * @param $openid * @param int $ ...
- Kafka:ZK+Kafka+Spark Streaming集群环境搭建(二十九):推送avro格式数据到topic,并使用spark structured streaming接收topic解析avro数据
推送avro格式数据到topic 源代码:https://github.com/Neuw84/structured-streaming-avro-demo/blob/master/src/main/j ...
- EasyCamera海康摄像机向EasyDarwin云平台推送音视频数据的缓存设计
本文转自EasyDarwin团队成员Alex的博客:http://blog.csdn.net/cai6811376 EasyCamera在向EasyDarwin云平台推送音视频数据时,有时一个I帧会很 ...
- Java企业微信开发_05_消息推送之发送消息(主动)
一.本节要点 1.发送消息与被动回复消息 (1)流程不同:发送消息是第三方服务器主动通知微信服务器向用户发消息.而被动回复消息是 用户发送消息之后,微信服务器将消息传递给 第三方服务器,第三方服务器接 ...
- 微信公众号第三方 推送component_verify_ticket协议
整了一天,终于弄明白了 component_verify_ticket 怎么获取的了.在此先批一下微信公众号平台,文档又没写清楚,又没有客服,想搞哪样哈! 好,回归正题. 第一,先通过开发者资质认证, ...
- 【Python撩妹合集】微信聊天机器人,推送天气早报、睡前故事、精美图片分享
福利时间,福利时间,福利时间 如果你还在为不知道怎么撩妹而烦恼,不知道怎么勾搭小仙女而困惑,又或者不知道怎么讨女朋友欢心而长吁短叹. 那么不要犹豫徘徊,往下看.接下来我会分享怎么使用 Python 实 ...
- 利用python对微信自动进行消息推送
from wxpy import * #该库主要是用来模拟与对接微信操作的 import requests from datetime import datetime import time impo ...
- 微信公众平台主动推送消息(asp.net)
/// <summary> /// MD5 32位加密 /// </summary> /// <param name=" ...
随机推荐
- Java中子类能继承父类的私有属性吗?
前段时间去听老师讲课的时候,老师告诉我子类是可以继承父类所有的属性和方法的.当时我是极其疑惑的,因为之前学校考试时这个考点我记得很清楚:子类只能继承父类的非私有属性和方法.老师给我的解释是这样的--先 ...
- ORA-04028: cannot generate diana for object xxx
在ORACLE数据库(10.2.0.5.0)上修改一个包的时候,编译有错误,具体错误信息为"ORA-04028: cannot generate diana for object xxx&q ...
- 重温.NET下Assembly的加载过程
最近在工作中牵涉到了.NET下的一个古老的问题:Assembly的加载过程.虽然网上有很多文章介绍这部分内容,很多文章也是很久以前就已经出现了,但阅读之后发现,并没能解决我的问题,有些点写的不是特别详 ...
- 微信 Tinker 的一切都在这里,包括源码
最近半年以来,Android热补丁技术热潮继续爆发,各大公司相继推出自己的开源框架.Tinker在最近也顺利完成了公司的审核,并非常荣幸的成为github.com/Tencent上第一个正式公开的项目 ...
- Attribute name "aphmodel" associated with an element type "mxg" must be followed by the ' = ' charac
1.错误描述 org.apache.batik.transcoder.TranscoderException: null Enclosed Exception: Attribute name &quo ...
- java重写和重载
方法的重载: 在一个类中的两个或两个以上的方法,他们方法名相同但是参数列表不同,这种方式称为方法的重载,方法的重载是实现多态性的方式之一. 参数列表不同指的是参数的个数不同或相同的个数但顺序不同或者类 ...
- Linux显示邮件状态等信息
Linux显示邮件状态等信息 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ finger -l Login: youhaidong Name: youhaid ...
- 一款PHP环境整合工具—VertrigoServ介绍
Vertrigo简介 VertrigoServ 是一个Windows平台下的非常专业的.易于安装的免费网络开发环境,它集成了Apache, PHP, MySQL, SQLite, SQLiteMana ...
- docker进阶-搭建私有企业级镜像仓库Harbor
为什么要搭建私有镜像仓库 对于一个刚刚接触Docker的人来说,官方的Docker hub是用于管理公共镜像.既然官方提供了镜像仓库我们为什么还要去自己搭建私有仓库呢?虽然也可以托管私有镜像.我们 ...
- 【编程笔记】Unity3D语言的类型系统--C#的类型系统
几乎所有的编程语言都有自己的类型系统. 而编程语言更是常常按照其类型系统而被分为强类型语言/弱类型语言.安全类型语言/不安全类型语言.静态类型语言/动态类型语言等. 而C#的类型系统是静态.安全,并且 ...