原推送引用: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. nginx笔记3-负载均衡算法

    1.nginx测试:先从官网下载nginx 官网网址为:http://nginx.org/  然后找到stable version的版本下载,因为这版本是最稳定的,不要去下载最新,因为不稳定,如下图: ...

  2. Hama顶点编程

    Hama是基于HDFS上的BSP模型实现. Apache Hame是Google Pregel的开源实现 Pregel是Google提出的一个面向大规模图计算的通用编程模型.许多实际应用中都涉及到大型 ...

  3. python 循环语句 函数 模块

    python循环语句 while循环语法结构 当需要语句不断的重复执行时,可以使用while循环 while expression: while_suite 语句ehile_suite会被连续不断的循 ...

  4. linux dhcp搭建及pxe无人值守装机

    DHCP动态主机配置协议:由IETF组织制定,用来简化主机ip地址分配管理可以自动分配的入网参数ip地址/子网掩码/广播地址默认网关地址DNS服务器地址 ----------------------- ...

  5. 2.5 非透明PCI桥

    PCI桥规范定义了透明桥的实现规则,本篇在第2.3.1节中详细介绍了这种桥片.通过透明桥,处理器系统可以以HOST主桥为根节点,建立一颗PCI总线树,在这个树上的PCI设备共享同一个PCI总线域上的地 ...

  6. 错误:readline/readline.h:没有那个文件或目录解决方法

    curl -R -O http://www.lua.org/ftp/lua-5.3.0.tar.gz tar zxf lua-5.3.0.tar.gz cd lua-5.3.0 make linux ...

  7. dojo中引入FusionCharts柱状图报错

    1.今天,做项目的过程中,我发现Java后台查询的数据都是正确的,并且拼接成JSON格式也正确,但是传到JSP页面时,图无法显示出来还报错,后来经过检查发现是JavaScript和引入FusionCh ...

  8. 错误代码: 1242 Subquery returns more than 1 row

    1. 错误描述 1 queries executed, 0 success, 1 errors, 0 warnings 查询:SELECT t.id, DATE_FORMAT( t.statisTim ...

  9. day8(字符串操作)

    一.字符串操作 1.index  #返回字符串的索引值 s = "Hello word" print(s.index('o')) 2.isalnum #检测字符串是否由字母和数字组 ...

  10. Django学习-14-分页功能实例

    首先创建一个制作page的工具类                     utils                         --page_make.py                    ...