当前位置: 首页 > 编程日记 > 正文

MapReduce_wordcount

测试数据:

[hadoop@h201 mapreduce]$ more counttext.txt
hello mama
hello baba
hello word
cai wen wei
mama baba jiejie gege
gege jiejie didi
meimei jiejie
didi mama
ayi shushu
ayi mama
hello mama
hello baba
hello word
cai wen wei
mama baba jiejie gege
gege jiejie didi
meimei jiejie
didi mama
ayi shushu
ayi mama
hello mama
hello baba
hello word
cai wen wei
mama baba jiejie gege
gege jiejie didi
meimei jiejie
didi mama
ayi shushu
ayi mama
hello mama
hello baba
hello word
cai wen wei
mama baba jiejie gege
gege jiejie didi
meimei jiejie
didi mama
ayi shushu
ayi mama
hello mama
hello baba
hello word
cai wen wei
mama baba jiejie gege
gege jiejie didi
meimei jiejie
didi mama
ayi shushu
ayi mama

vim WordCount2.java

 1 package MapReduce;
 2 
 3 import java.io.*;
 4 import org.apache.hadoop.conf.Configuration;
 5 import org.apache.hadoop.fs.Path;
 6 import org.apache.hadoop.io.IntWritable;
 7 import org.apache.hadoop.io.Text;
 8 import org.apache.hadoop.mapreduce.Job;
 9 import org.apache.hadoop.mapreduce.Mapper;
10 import org.apache.hadoop.mapreduce.Reducer;
11 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
12 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
13 
14 public class WordCount2{
    private static final String INPUT_PATH = "hdfs://h201:9000/user/hadoop/counttext.txt";
      private static final String OUTPUT_PATH = "hdfs://h201:9000/user/hadoop/output";
15 public static class WordCount2Mapper extends Mapper<Object,Text,Text,IntWritable>{ 16 private final static IntWritable one = new IntWritable(1); 17 private Text word = new Text(); 18 19 public void map(Object key,Text value,Context context) throws IOException, InterruptedException { 20 String[] words = value.toString().split(" "); 21 for (String str: words){ 22 word.set(str); 23 context.write(word,one); 24 } 25 } 26 } 27 28 public static class WordCount2Reducer extends Reducer<Text,IntWritable,Text,IntWritable> { 29 public void reduce(Text key,Iterable<IntWritable> values,Context context) throws IOException, InterruptedException { 30 int total=0; 31 for (IntWritable val : values){ 32 total++; 33 } 34 context.write(key, new IntWritable(total)); 35 } 36 } 37 38 public static void main (String[] args) throws Exception{ 39 Configuration conf = new Configuration(); 40 conf.set("mapred.jar","wc1.jar"); 41 Job job = new Job(conf, "wordcount"); 42 job.setJarByClass(WordCount2.class); 43 job.setMapperClass(WordCount2Mapper.class); 44 job.setReducerClass(WordCount2Reducer.class); 45 job.setOutputKeyClass(Text.class); 46 job.setOutputValueClass(IntWritable.class); 47 FileInputFormat.addInputPath(job, new Path(args[0])); 48 FileOutputFormat.setOutputPath(job, new Path(args[1])); 49 //FileInputFormat.addInputPath(job, new Path(INPUT_PATH));addInputPaths多路径50 //FileOutputFormat.setOutputPath(job, new Path(OUTPUT_PATH)); 51 System.exit(job.waitForCompletion(true) ? 0 : 1); 52 } 53 }

[hadoop@h201 mapreduce]$ /usr/jdk1.7.0_25/bin/javac WordCount2.java
Note: WordCount2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[hadoop@h201 mapreduce]$ ls
counttext.txt  WordCount2.class  WordCount2.java  WordCount2$WordCount2Mapper.class  WordCount2$WordCount2Reducer.class
[hadoop@h201 mapreduce]$ /usr/jdk1.7.0_25/bin/jar cvf wc1.jar WordCount2*class
added manifest
adding: WordCount2.class(in = 1531) (out= 815)(deflated 46%)
adding: WordCount2$WordCount2Mapper.class(in = 1831) (out= 783)(deflated 57%)
adding: WordCount2$WordCount2Reducer.class(in = 1623) (out= 670)(deflated 58%)
[hadoop@h201 mapreduce]$ ls
counttext.txt  wc1.jar  WordCount2.class  WordCount2.java  WordCount2$WordCount2Mapper.class  WordCount2$WordCount2Reducer.class
[hadoop@h201 mapreduce]$ hadoop jar wc1.jar WordCount2 hdfs://h201:9000/user/hadoop/counttext.txt hdfs://h201:9000/user/hadoop/output
18/03/09 23:33:38 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
18/03/09 23:33:39 INFO client.RMProxy: Connecting to ResourceManager at h201/192.168.121.132:8032
18/03/09 23:33:55 WARN mapreduce.JobResourceUploader: Hadoop command-line option parsing not performed. Implement the Tool interface and execute your application with ToolRunner to remedy this.
18/03/09 23:34:05 INFO input.FileInputFormat: Total input paths to process : 1
18/03/09 23:34:06 INFO mapreduce.JobSubmitter: number of splits:1
18/03/09 23:34:06 INFO Configuration.deprecation: mapred.jar is deprecated. Instead, use mapreduce.job.jar
18/03/09 23:34:09 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1516635595760_0001
18/03/09 23:34:21 INFO impl.YarnClientImpl: Submitted application application_1516635595760_0001
18/03/09 23:34:21 INFO mapreduce.Job: The url to track the job: http://h201:8088/proxy/application_1516635595760_0001/
18/03/09 23:34:21 INFO mapreduce.Job: Running job: job_1516635595760_0001
18/03/09 23:35:32 INFO mapreduce.Job: Job job_1516635595760_0001 running in uber mode : false
18/03/09 23:35:32 INFO mapreduce.Job:  map 0% reduce 0%
18/03/09 23:36:33 INFO mapreduce.Job:  map 100% reduce 0%
18/03/09 23:36:45 INFO mapreduce.Job:  map 100% reduce 100%
18/03/09 23:36:47 INFO mapreduce.Job: Job job_1516635595760_0001 completed successfully
18/03/09 23:36:47 INFO mapreduce.Job: Counters: 49
        File System Counters
                FILE: Number of bytes read=1366
                FILE: Number of bytes written=221143
                FILE: Number of read operations=0
                FILE: Number of large read operations=0
                FILE: Number of write operations=0
                HDFS: Number of bytes read=747
                HDFS: Number of bytes written=101
                HDFS: Number of read operations=6
                HDFS: Number of large read operations=0
                HDFS: Number of write operations=2
        Job Counters
                Launched map tasks=1
                Launched reduce tasks=1
                Data-local map tasks=1
                Total time spent by all maps in occupied slots (ms)=55286
                Total time spent by all reduces in occupied slots (ms)=8704
                Total time spent by all map tasks (ms)=55286
                Total time spent by all reduce tasks (ms)=8704
                Total vcore-seconds taken by all map tasks=55286
                Total vcore-seconds taken by all reduce tasks=8704
                Total megabyte-seconds taken by all map tasks=56612864
                Total megabyte-seconds taken by all reduce tasks=8912896
        Map-Reduce Framework
                Map input records=50
                Map output records=120
                Map output bytes=1120
                Map output materialized bytes=1366
                Input split bytes=107
                Combine input records=0
                Combine output records=0
                Reduce input groups=13
                Reduce shuffle bytes=1366
                Reduce input records=120
                Reduce output records=13
                Spilled Records=240
                Shuffled Maps =1
                Failed Shuffles=0
                Merged Map outputs=1
                GC time elapsed (ms)=1264
                CPU time spent (ms)=4210
                Physical memory (bytes) snapshot=223772672
                Virtual memory (bytes) snapshot=2148155392
                Total committed heap usage (bytes)=136712192
        Shuffle Errors
                BAD_ID=0
                CONNECTION=0
                IO_ERROR=0
                WRONG_LENGTH=0
                WRONG_MAP=0
                WRONG_REDUCE=0
        File Input Format Counters
                Bytes Read=640
        File Output Format Counters
                Bytes Written=101
[hadoop@h201 mapreduce]$ hadoop fs -lsr /user/hadoop/output
lsr: DEPRECATED: Please use 'ls -R' instead.
18/03/09 23:37:40 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
-rw-r--r--   2 hadoop supergroup          0 2018-03-09 23:36 /user/hadoop/output/_SUCCESS
-rw-r--r--   2 hadoop supergroup        101 2018-03-09 23:36 /user/hadoop/output/part-r-00000
[hadoop@h201 mapreduce]$ hadoop fs -cat /user/hadoop/output/part-r-00000
18/03/09 23:39:25 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
ayi     10
baba    10
cai     5
didi    10
gege    10
hello   15
jiejie  15
mama    20
meimei  5
shushu  5
wei     5
wen     5
word    5

转载于:https://www.cnblogs.com/jieran/p/8537012.html

相关文章:

Appium+python自动化(八)- 初识琵琶女Appium(千呼万唤始出来,犹抱琵琶半遮面)- 下(超详解)...

​简介 通过上一篇宏哥给各位小伙伴们的引荐&#xff0c;大家移动对这位美女有了深刻的认识&#xff0c;而且她那高超的技艺和婀娜的身姿久久地浮现在你的脑海里&#xff0c;是不是这样呢&#xff1f;&#xff1f;&#xff1f;不要害羞直接告诉宏哥&#xff1a;是&#xff0c;就…

蜻蜓resin服务器虚拟目录的设置

首先&#xff0c;别急着打开服务器先&#xff0c;接住打开resin主目录下的conf文件夹的resin.conf文件&#xff0c;老规矩&#xff0c;备份先&#xff0c;mv resin.conf resin.conf.bak然后vi resin.conf 文件&#xff0c;找到如下这段代码&#xff1a;1 <!--configures the…

【java】兴唐第十节课知识点总结

1、使用main里的成员方法也要实例化对象吗&#xff1f; 必须实例化 ///重点&#xff01; 2、在成员方法中调用另一个成员方法可以直接调用&#xff08;前面省略一个this.&#xff09; 3、 \n也可以在java里用 4、null可以是除了基本数据类型外的任何数据类型 5、基本数据类…

SharePoint2010是个什么东西

Microsoft SharePoint Foundation is an application that is built on top of Internet Information Services (IIS) and the Microsoft ASP.NET Framework. Microsoft SharePoint Foundation 是架构在IIS和ASP.NET Framework上的一个应用程序。IIS是与互联网站点相关的&#…

Linux Shell高级技巧(目录)

为了方便我们每个人的学习&#xff0c;这里将给出Linux Shell高级技巧五篇系列博客的目录以供大家在需要时参阅和查找。 Linux Shell高级技巧(一) http://www.cnblogs.com/stephen-liu74/archive/2011/12/22/2271167.html一、将输入信息转换为大写字符后再进行条件判断二、为调…

Keras卷积+池化层学习

转自&#xff1a;https://keras-cn.readthedocs.io/en/latest/layers/convolutional_layer/ https://keras-cn.readthedocs.io/en/latest/layers/pooling_layer/ 1.con1D keras.layers.convolutional.Conv1D(filters, kernel_size, strides1, paddingvalid, dilation_rate1, ac…

【Java】阿里巴巴java开发手册总结(我能看懂的)

尽管这本《手册》句句是精华&#xff0c;但由于我还是个菜鸟&#xff0c;这里仅作&#xff08;我能用的到的&&我能看懂的&#xff09;的笔记 1.1命名风格 1、类名用UpperCamelCase的风格 2、方法名、参数名、成员变量、局部变量都统一用lowerCameCase的风格&#xff…

关于maya与max互导FBX出现错误的解决方案。

因为自己实在是不愿意一次又一次把时间浪费在导入导出的问题上。每一次都是多试几次才成功&#xff0c;也没有真正去测试这个东西。但是今天实在是碰到了错误中的极品了。最后还是决定写下来。。算是给自己做笔记吧。。大家如果在导入导出的时候遇到一些问题不妨试试以下几种方…

AS3.0中的显示编程(六)-- 几何结构

几何结构&#xff0c;主要是完成Flash编程中&#xff0c;一些和几何相关的内容。如显示对象的变形角度、公式计算等。可能很多人和我一样&#xff0c;高中学的几何知识&#xff0c;差不多都已经还给老师了。不过也不用太担心&#xff0c;因为一般情况下&#xff0c;我们也用不到…

Win10命令行激活 电脑组装

系统激活&#xff1a; 1. 管理员身份运行 cmd 2. slmgr.vbs /upk //卸载产品密匙 3. slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX //安装 4. slmgr /skms zh.us.to …

【java】兴唐第十五节课

知识点&#xff1a; 1、定义包名不能以java.为开头。 2、获取系统时间的方法&#xff1a; 注意&#xff1a; &#xff08;1&#xff09; 引入Date类时&#xff0c;引入的是java.util.Date 而不是java.sql.Date(后者是前者的子类)。 代码实现 Date date new Date(); System.o…

SQL Server 日期和时间相关的数据类型有两种

SQL Server 日期和时间相关的数据类型有两种&#xff1a;DateTime和SmallDateTime。 DateTime:需要8个字节&#xff0c;前4个字节用1900年1月1日以后的天数表示日期&#xff0c;后4个字节表示一天中的时间。支持的日期范围&#xff1a;1/1/1753 12:00:00 AM到12/31/9999 11:59…

序列化pickle

import pickle d { name:alex, role:police, blood: 76, weapon:AK47 } d_dump pickle.dumps(d) #序列化 print (pickle.loads(d_dump)) #反序列化 f open(game.pkl, wb) pickle.dump(d, f) #First in first out (FIFO) pickle.dump(alive_players, f) dump 写入文件 du…

T-SQL笔记3:事务、锁定和并发

T-SQL笔记3&#xff1a;事务、锁定和并发 本章摘要 1&#xff1a;事务 1.1&#xff1a;显式事务 1.2&#xff1a;使用DBCC OPENTRAN显示最早的活动事务 2&#xff1a;锁定 2.1&#xff1a;查看锁的活动 3&#xff1a;并发影响及隔离级别 3.1&#xff1a;并发影响 3.2&#xff1…

几种常用数据库比较

目前&#xff0c;商品化的数据库管理系统以关系型数据库为主导产品&#xff0c;技术比较成熟。面向对象的数据库管理系统虽然技术先进&#xff0c;数据库易于开发、维护&#xff0c;但尚未有成熟的产品。国际国内的主导关系型数据库管理系统有Oracle、Sybase、INFORMIX和INGRES…

成功将BlogEngine 1.5 升级到了BlogEngine 2.0

使用BlogEngine.Net博客系统有两年时间了。官方的最新版本已经出到了2.5。但它是基于.net4.0的。也就是说服务器必须安装.net4.0&#xff0c;运行环境必须选择4.0。出于移植性的考虑。我决定将我的博客升级到2.0。BlogEngine.Net2.0是继续.net2.0的。虽说必须安装.net 3.5&…

【java】4.27上课及做作业时遇到的问题及第十六节课笔记整理

注意&#xff1a; 部分知识点只在eclipse运行环境中适用 1、字符串转化为字符数组的方法: 代码实现&#xff1a; char[] strcs text.toCharArray();2、字符数字转化为字符串 String reStr new String(re,0 ,position);3、打包及 引包的方法 &#xff08;1&#xff09; 用ex…

【Android】基于A星寻路算法的简单迷宫应用

简介 基于【漫画算法-小灰的算法之旅】上的A星寻路算法&#xff0c;开发的一个Demo。目前实现后退、重新载入、路径提示、地图刷新等功能。没有做太多的性能优化&#xff0c;算是深化对A星寻路算法的理解。 界面预览: 初始化: 寻路: 后退: 提示: 完成: 刷新地图: 下载地址: 项目…

[转]SQL 约束讲解

约束主要包括&#xff1a; •NOT NULL •UNIQUE •PRIMARY KEY •FOREIGN KEY •CHECK •DEFAULT 1、not null &#xff1a;用于控制字段的内容一定不能为空&#xff08;NULL&#xff09;。 用法 &#xff1a;Create table MyTable ( id …

JSON 转 VO

需求 将获取的json数据直接转为vo 解决 利用net.sf.json.JSONObject的toBean() 确保json中的key值和vo中的字段名称一致 JSONObject jsonObject new JSONObject();UserVO vo new UserVO(); vo (UserVO) net.sf.json.JSONObject.toBean(jsonObject, UserVO.class);参考文档地…

怎样查看一个端口有无开启

有时候我们需要确定一下某个端口有无开启&#xff0c;有两种方法。 方法 1&#xff1a;查看一个端口有无开启的最简单方法 查看端口有无开启&#xff0c;需要在dos里使用命令来完成。这个命令就是&#xff1a; netstat -ano这个命令能显示当前电脑有哪些端口正在使用&#xff0…

一道SQL统计试题

根据上图A表和B表&#xff0c;按照年份和地区生成1至12个月的数据&#xff0c;结果如下&#xff1a; 方法一&#xff1a; select YEAR,AreaName, MAX(case Month when 1 then Money else 0 end) as [1月], MAX(case Month when 2 then Money else 0 end) as [2月], MAX(case Mo…

【单片机】时钟周期 器械周期 指令周期的关系

1、 时钟周期&#xff08;振荡周期&#xff09;&#xff1a;始终周期也称振荡周期&#xff0c;定义为时钟频率的倒数。时钟周期是计算机中最基本的、最小的单位。在一个始终周期内&#xff0c;CPU仅完成一个最基本的动作。时钟周期是一个时间的量。始终周期表示了SDRAM&#xf…

Painting A Board --POJ 1691

1、题目类型&#xff1a;暴力法、DFS。 2、解题思路&#xff1a;题意&#xff0c;一块大的矩形区域的被分成多个矩形区域&#xff0c;现在要给不同的区域涂上不同的颜色&#xff0c;有不同颜色的刷子可以提供&#xff0c;每个刷子可以刷一种不同的颜色。每刷一次&#xff0c;将…

《JavaScript高级程序设计》读书笔记【一】

JavaScript介绍 ECMAScript&#xff0c;由ECMA-262定义&#xff0c;提供核心语言功能&#xff1b;  文档对象模型&#xff08;DOM&#xff09;&#xff0c;提供访问和操作网页内容的方法和接口&#xff1b;  浏览器对象模型&#xff08;BOM&#xff09;&#xff0c;提供与浏…

上不了名校?可以在 GitHub 上读他们的课程

今天开始&#xff0c;全国各大区域的高考成绩陆续公布&#xff0c;又到了几家欢喜几家愁的时刻&#xff0c;如果你准备报考计算机相关专业&#xff0c;但是又由于分数不高而苦恼。别担心&#xff0c;在 GitHub 上有着大量的名校教学资源&#xff0c;即使上不了名校&#xff0c;…

【java】各种方法的使用(不定期更新)

疑难杂症篇 1、输入一个字符的方法 问题在于Scanner中没有一个类似于nextInt()之类的函数。 代码实现 char num scanner.next().charAt(0);2、将字符串转化为数字 没啥问题就是记不下来 代码实现&#xff1a; int a1 Integer.parseInt(i1);3、字符串转化为字符数组的方法 …

SQL SERVER 触发器示例

触发器是一种特殊的存储过程。 触发器语法 &#xff1a; CREATE TRIGGER trigger_name ON { table | view } [ WITH ENCRYPTION ] { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ DELETE ] [ UPDATE ] } [ WITH APPEND ] [ NOT FOR REPLICATION ] AS sql_statement [ ...n ] 示…

vc数据库知识

在连接SQL数据库时&#xff0c;数据库的链接: _bstr_t strConn"ProviderSQLOLEDB.1;Data Source.;Initial Catalogdb_test;Integrated SecuritySSPI;Persist Security InfoFalse"; _ConnectionPtr m_pConnection; m_pConnection.CreateInstance(__uuidof(connection)…

jmeter 测试 api 接口方法

双击 “jmeter.bat” 打开 Jmeter 页面&#xff0c;如下图所示。 右击“测试计划”&#xff0c;添加 -> Theaders&#xff08;Users&#xff09; -> 线程组 在线程组中可以设置线程数、并发数、循环数等。 下面开始进行几种 jmeter 的接口测试方法。 1、get 请求配置 右击…