原推送引用: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. SpringCloud入门1-服务注册与发现(Eureka)

    前言 Oracle转让Java,各种动态语言的曝光率上升,Java工程师的未来在哪里?我觉得Spring Cloud让未来有无限可能.拖了半年之久的Spring Cloud学习就从今天开始了.中文教材 ...

  2. C语言拼接字符串以及进制转换

    #include<stdio.h> #include<stdlib.h> #include<string.h> char *join1(char *, char*) ...

  3. mysql varchar vs oracle varchar2

    1.错误提示: mysql的Data truncation: Data too long for column 'path' at row 1 错误原因: 1.字段过长而导致出错的, 2. 可能是因为 ...

  4. R语言︱贝叶斯网络语言实现及与朴素贝叶斯区别(笔记)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 一.贝叶斯网络与朴素贝叶斯的区别 朴素贝叶斯的 ...

  5. FusionCharts重写单系列图

    /** * @Title:FusionChart.java * @Package:com.yhd.chart.model * @Description:封装FusionChart单系列图 * @aut ...

  6. Redis相关指令文档

    连接控制 QUIT 关闭连接 AUTH (仅限启用时)简单的密码验证 适合全体类型的命令 EXISTS key 判断一个键是否存在;存在返回 1;否则返回0; DEL key 删除某个key,或是一系 ...

  7. Windows下的Memcache安装:

    Windows下的Memcache安装:1. 下载memcache的windows稳定版,解压放某个盘下面,比如在c:\memcached2. 在终端(也即cmd命令界面)下输入 'c:\memcac ...

  8. R语言︱R社区的简单解析(CRAN、CRAN Task View)

    笔者寄语:菜鸟笔者一直觉得r CRAN离我们大家很远,在网上也很难找到这个社区的全解析教程,菜鸟我早上看到一篇文章提到了这个,于是抱着学渣学习的心态去看看这个社团的磅礴.威武. CRAN(The Co ...

  9. 求sum=1+111+1111+........+1....111 .

    1,思路 大数相加,若直接使用int,或者long都会超出长度,因此考虑使用String存储. 2,代码 public class LargeNumAdd { public static void m ...

  10. Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.annotation.Around

    1.错误描述 INFO:2015-05-01 11:12:15[localhost-startStop-1] - Root WebApplicationContext: initialization ...