原推送引用: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统计的更多相关文章

  1. 微信小程序--消息推送配置Token令牌错误校验失败如何解决

    微信开放第三方API接口, 申请地址: https://mp.weixin.qq.com/advanced/advanced?action=interface&t=advanced/inter ...

  2. php 微信客服信息推送失败 微信重复推送客服消息 40001 45047

    /*** * 微信客服发送信息 * 微信客服信息推送失败 微信重复推送客服消息 40001 45047 * 递归提交到微信 直到提交成功 * @param $openid * @param int $ ...

  3. 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 ...

  4. EasyCamera海康摄像机向EasyDarwin云平台推送音视频数据的缓存设计

    本文转自EasyDarwin团队成员Alex的博客:http://blog.csdn.net/cai6811376 EasyCamera在向EasyDarwin云平台推送音视频数据时,有时一个I帧会很 ...

  5. Java企业微信开发_05_消息推送之发送消息(主动)

    一.本节要点 1.发送消息与被动回复消息 (1)流程不同:发送消息是第三方服务器主动通知微信服务器向用户发消息.而被动回复消息是 用户发送消息之后,微信服务器将消息传递给 第三方服务器,第三方服务器接 ...

  6. 微信公众号第三方 推送component_verify_ticket协议

    整了一天,终于弄明白了 component_verify_ticket 怎么获取的了.在此先批一下微信公众号平台,文档又没写清楚,又没有客服,想搞哪样哈! 好,回归正题. 第一,先通过开发者资质认证, ...

  7. 【Python撩妹合集】微信聊天机器人,推送天气早报、睡前故事、精美图片分享

    福利时间,福利时间,福利时间 如果你还在为不知道怎么撩妹而烦恼,不知道怎么勾搭小仙女而困惑,又或者不知道怎么讨女朋友欢心而长吁短叹. 那么不要犹豫徘徊,往下看.接下来我会分享怎么使用 Python 实 ...

  8. 利用python对微信自动进行消息推送

    from wxpy import * #该库主要是用来模拟与对接微信操作的 import requests from datetime import datetime import time impo ...

  9. 微信公众平台主动推送消息(asp.net)

    /// <summary>        /// MD5 32位加密        /// </summary>        /// <param name=" ...

随机推荐

  1. AGC010 - B: Boxes

    原题链接 题意简述 给出一个由个数构成的环,每次可以选择一个位置并从这个数起顺时针依次对每个数-1,-2,-3,-,-n.问能否将所有数全变为0. 分析 考虑一次操作对环带来了什么影响. (在后加一个 ...

  2. tcp/ip 卷一 读书笔记(5)arp和rarp 同网段和不同网段之间的通信过程

    arp和rarp 同网段和不同网段之间的通信过程 IPv6中已经没有arp rarp协议,所以这里都是IPv4. 链路层使用以太网地址来确定目的地址,应用则常使用ip地址通信 arp协议是指从ip地址 ...

  3. Day5模块-shutil模块

    参考博客:http://www.cnblogs.com/wupeiqi/articles/4963027.html shutil模块是高级的文件.文件夹.压缩处理的模块.比如文件的copy.压缩等. ...

  4. 电脑中dll文件丢失怎么恢复?

    DLL文件是Windows系统中的动态链接文件,我们在运行程序时都必须链接到dll文件,如果缺少了则无法正常运行,相信大家都会遇到dll文件缺失的情况,那么电脑中dll文件丢失怎么恢复?下面装机之家分 ...

  5. mysql 主从同步 mysql代理服务器

    搭建mysql主从同步(实现数据自动备份)实例:把主机192.168.4.100的数据库配置为主机192.168.4.99的从数据库 主数据库服务器配置修改配置文件: [root@mysql ~]# ...

  6. HashMap和Hashtable的异同点

    HashMap和Hashtable的异同点 不同点: 1.HashMap的父类是AbstractMap,而Hashtable的父类是Dictiionary: 2.HashMap的key和value可以 ...

  7. freemarker报错之四

    1.错误描述 五月 28, 2014 9:56:48 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proce ...

  8. Servlet.service() for Servlet jsp threw exception javax.servlet.ServletException:File &quot;/pageFoo

    1.错误描述 Servlet.service() for Servlet jsp threw exception javax.servlet.ServletException:File "/ ...

  9. C# post数据时 出现如下错误: System.Net.WebException: 操作超时

    net(客户端)调用IIS(服务端)出现503后,就报操作超时错误 问题描述: 服务端环境: IIS 客户端环境: windowsxp + iis + .net 调用时出现如下错误: System.N ...

  10. 如何创建Filter的属性页

    本篇文档我们将要讲述如何给一个filter创建一个属性页,通过CBasePropertyPage基类.这篇文档的实例代码演 示了创建属性页的步骤,这里我们假设我们要创建属性页的视频filter支持饱和 ...