目录
[一、对于 sogou_500w_utf 数据,使用 MapReduce 编程模型完成对以下数据的分析任务](#一、对于 sogou_500w_utf 数据,使用 MapReduce 编程模型完成对以下数据的分析任务)
[1. 统计 2011-12-30 日搜索记录,每个时间段的搜索次数](#1. 统计 2011-12-30 日搜索记录,每个时间段的搜索次数)
[(2) 源代码](#(2) 源代码)
[2. 统计 2011-12-30 日 3 点至 4 点之间,哪些 UID 访问了搜狗引擎。](#2. 统计 2011-12-30 日 3 点至 4 点之间,哪些 UID 访问了搜狗引擎。)
[二、有两个输入文件 A 和 B,使用 MapReduce 编程合并文件,得到输出文件 C](#二、有两个输入文件 A 和 B,使用 MapReduce 编程合并文件,得到输出文件 C)
[1. 输入文件A和B如下](#1. 输入文件A和B如下)
[2. 通过MapReduce编程合并文件得到outputC](#2. 通过MapReduce编程合并文件得到outputC)
[3. 源代码](#3. 源代码)
一、对于 sogou_500w_utf 数据,使用 MapReduce 编程模型完成对以下数据的分析任务
1. 统计 2011-12-30 日搜索记录,每个时间段的搜索次数
(每小时为一个单位,比如 0 点钟多少次,1 点钟多少次,2 点钟多少次,一直到 23 点多少次)
(1)运行截图
bash
hadoop jar /home/2130502441ryx/SearchCountJob.jar org/ryx/SearchCountJob /sogou.500.utf8 /output5
![](https://img-blog.csdnimg.cn/direct/9d8788c87e6447b19b798d4f9b90406b.png)
bash
hdfs dfs -ls /output5
hdfs dfs -cat /output5/part-r-00000
![](https://img-blog.csdnimg.cn/direct/f19a0f6a4be24089a14f1992662e5f35.png)
(2) 源代码
① SearchCountMapper
![](https://img-blog.csdnimg.cn/direct/34e831ebd0b34701a73fe219dd69e7f7.png)
② SearchCountReduct
![](https://img-blog.csdnimg.cn/direct/5d899e9ed320430b8c63f8e2de696d7f.png)
③ SearchCountJob
![](https://img-blog.csdnimg.cn/direct/81d6c048c2ab462999bc1e806a1d5c1d.png)
2. 统计 2011-12-30 日 3 点至 4 点之间,哪些 UID 访问了搜狗引擎。
(1)运行截图
bash
hadoop jar /home/2130502441ryx/UIDCountJob.jar org/ryx/SogouDriver /sogou.500.utf8 /output7
(下面截图贴错了,上面的运行命令才是正确的)
![](https://img-blog.csdnimg.cn/direct/6182e0fbc9584c6ab8f39cafecef43e2.png)
bash
hdfs dfs -ls /output7
hdfs dfs -cat /output7/part-r-00000
![](https://img-blog.csdnimg.cn/direct/9ccfad137ffe45949b2f3178fcc9d0bf.png)
(2)源代码
SogouMapper.java
![](https://img-blog.csdnimg.cn/direct/d1e14f25f31749f6a0eca4da528a6019.png)
SogouReducer.java
![](https://img-blog.csdnimg.cn/direct/cfa119538c3047a8a2fa242f6d99cde9.png)
SogouDriver.java
![](https://img-blog.csdnimg.cn/direct/6c165833106d4b379c5814c5eef7ae53.png)
二、有两个输入文件 A 和 B,使用 MapReduce 编程 合并文件 ,得到 输出文件 C
输入文件 A 的样例如下:
20150101 x
20150102 y
20150103 x
20150104 y
20150105 z
20150106 x
输入文件 B 的样例如下:
20150101 y
20150102 y
20150103 x
20150104 z
20150105 y
根据输入文件 A 和 B 合并得到的输出文件 C 的样例如下:
20150101 x
20150101 y
20150102 y
20150103 x
20150104 y
20150104 z
20150105 y
20150105 z
20150106 x
1. 输入文件A和B如下
bash
hdfs dfs -cat /inputA
![](https://img-blog.csdnimg.cn/direct/e768684233a44715b2cbc08745064bde.png)
bash
hdfs dfs -cat /inputB
![](https://img-blog.csdnimg.cn/direct/7b3cea5e082d454b9d7ccb86e0337e22.png)
2. 通过MapReduce编程合并文件得到outputC
bash
hadoop jar /home/2130502441ryx/MergeFiles.jar org/ryx/MergeFiles /inputA /inputB /outputC
![](https://img-blog.csdnimg.cn/direct/e79837a53e9944eeb717a4d5923e8711.png)
bash
hdfs dfs -cat /outputC/part-r-00000
![](https://img-blog.csdnimg.cn/direct/cd3540405ddc4f93a1dd18b246a2700c.png)
3. 源代码
① MergeMapper
![](https://img-blog.csdnimg.cn/direct/3bf877ef34104b59ab824e0751361d73.png)
② MergeReducer
![](https://img-blog.csdnimg.cn/direct/18f2507d09964ca28994c797a04daf0d.png)
③ MergeFiles
![](https://img-blog.csdnimg.cn/direct/5d070df687c04dda94def3947a3a15e2.png)