Hadoop Streaming: c++编写uniq程序
来源:互联网 发布:nicelabel se软件下载 编辑:程序博客网 时间:2024/05/12 07:26
1. 描述
使用Hadoop streaming对输入数据的第一列进行uniq去重计算,采用c++编写map-reduce程序。
2. mapper程序
mapper.cpp
#include <iostream>#include <string>using namespace std;#define BUFFER_SIZE 102400#define DELIM "\t"int main(int argc, char** argv){ char buf[BUFFER_SIZE]; char *strCur = NULL; //读取第一个字段并输出 while(fgets(buf, BUFFER_SIZE-1, stdin)) { strCur = strtok(buf, DELIM); cout << buf << endl; } return 0;}
3. reducer
reducer.cpp
#include <string>#include <set>#include <iostream>using namespace std;int main(int argc, char** argv){ string key; set<string> myset; while(cin >> key) { myset.insert(key); } cout << myset.size() << endl; return 0;}
4. 测试数据
test.txt
a 15 1a 15 1a 15 1a 15 1b 20 1c 15 1c 15 1d 16 1a 16 1
5. 本地测试
$ g++ -o mapper mapper.cpp $ g++ -o reducer reducer.cpp $ cat test.txt | ./mapper | ./reducer 4
6. Hadoop streaming 测试
$ hadoop fs -put test.txt /user/test.txt$ hadoop streaming -input /user/test.txt / -output /user/tmp_1324 / -mapper ./mapper -reducer ./reducer / -file mapper -file reducer / -jobconf mapred.reduce.tasks=1 / -jobconf mapre.job.name="uniq_test"
7. 查看结果
$ hadoop fs -cat /user/tmp_1324/part-000004
- Hadoop Streaming: c++编写uniq程序
- Hadoop Streaming 实战: c++编写map&reduce程序
- 借助hadoop streaming,使用C++编写MapReduce程序
- Hadoop streaming 编写MapReduce程序-二次排序,多文件输入
- awk编写hadoop streaming 总结
- python Hadoop Streaming程序测试
- Python+hadoop Streaming编写的Map-Reduce程序与调试运行
- 用python + hadoop streaming 编写分布式程序的本地调试方法
- Python利用hadoop Streaming编写的Map-Reduce程序命令运行和本地调试运行
- 在Hadoop中使用Streaming编写MapReduce
- 用Bash Script编写Hadoop MapReduce Streaming
- Hadoop streaming编写mapper与reducer
- 用python + hadoop streaming 编写分布式程序(一) -- 原理介绍,样例程序与本地调试
- 使用dumbo开发hadoop streaming程序
- 使用dumbo开发hadoop streaming程序
- 【hadoop学习】在伪分布式hadoop上实践word count程序——c/c++ streaming版本(未完)
- Hadoop Streaming python c c++ perl 编程
- 【dumbo】【hadoop】使用dumbo开发hadoop streaming程序
- others
- 如何利用缓存服务器来负载均衡
- python 文件传输客户端程序
- 排序算法比较
- 【android基础学习之二】——基础控件ListView
- Hadoop Streaming: c++编写uniq程序
- 关于如何让LISTVIEW变“白”
- as3.0反射机制的一个限制
- 正则表达式在vb.net中的简单应用
- RadChart 中如何一个图表中的两个不同值的轴保持同一起点?
- 网络安全术语解释
- android bitmap 中RGB
- ASP.NET 前台按键捕捉响应脚本,捕捉按下某键触事件与,按下某键后弹起再触发事件
- struts2拦截器(4)