package com.bw.mr;

import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper; // yarn mr--->Mapper map Reducer reduce
// Mapper:四个泛型
//keyin :Map端输入的K值 keyin :偏移量
// hello word hello tom hello jim
//hello word 9 (hello word) String
// hello tom 17( hello tom)
// hello jim .....
//valuein: word
// hadoop 的api writeable
// keyout valueout ----> k(单词)
public class WCMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
Text t=new Text();
IntWritable i =new IntWritable(1);
@Override
// map端 分别和1 组装
protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context)
throws IOException, InterruptedException {
// hadoop Api " hello word hello tom" --->"hello"" word" hello tom
String splits[]= value.toString().split(" ");
// java hadoop
for(String word:splits) {
// word --->text
t.set(word);
// 上下文信息: map 端信息发出去 context 发出去
context.write(t, i);
}
}
}

  

package com.bw.mr;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer; // Mr :input map reduce output
// reducer reduce hello(1,1,1,1,1)-->hello(1+1+1+...)
// map(LongWriteable,text) --->(text,IntWriteable)\
// reduce (text,IntWriteable) ---->(text,IntWriteable)
// hello(1,1,1,1,1)-->
public class WCReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
// 重写 reduce 方法
@Override
// text :word Iterable (111111111111111)
protected void reduce(Text arg0, Iterable<IntWritable> arg1,
Reducer<Text, IntWritable, Text, IntWritable>.Context arg2) throws IOException, InterruptedException {
// reduce --->归并 ---》 word(1,1,1,1,...)---->word(count)
int count =0;
// 循环 。。。for
for(IntWritable i:arg1) {
count++;
}
// 输出最后 的结果
arg2.write(arg0,new IntWritable(count));
}
}

  

package com.bw.mr;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class WordCount {// 触发 启动类
public static void main(String[] args) throws Exception {
// 配置信息
Configuration conf = new Configuration();
// mr 程序 job
Job job = Job.getInstance(conf);
// job 运行 class
job.setJarByClass(WordCount.class);
//
job.setMapperClass(WCMapper.class);
// job:有关于 mr的全部 ----》jar包 (包含所有的四要素,所有的类)
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setReducerClass(WCReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
// job WC :mr:job 数据
FileInputFormat.addInputPath(job, new Path("hdfs://linux04:9000/aa.txt"));
// 是经过 mapreduce 之后的输出结果
FileOutputFormat.setOutputPath(job, new Path("hdfs://linux04:9000/aajiegou.txt"));
// job 要提交到集群上去的
job.waitForCompletion(true);
// jar ---->集群上传 -————》
// hadoop jar wordcountjar cn.beiwang.mr.Wordcount
// 1.8 hadoop jar hadoop jar jar hadoop jar wordcountjar 具体路径
}
}

  

用eclipce编写 MR程序 MapReduce的更多相关文章

  1. C#码农的大数据之路 - 使用C#编写MR作业

    系列目录 写在前面 从Hadoop出现至今,大数据几乎就是Java平台专属一般.虽然Hadoop或Spark也提供了接口可以与其他语言一起使用,但作为基于JVM运行的框架,Java系语言有着天生优势. ...

  2. 2 weekend110的mapreduce介绍及wordcount + wordcount的编写和提交集群运行 + mr程序的本地运行模式

    把我们的简单运算逻辑,很方便地扩展到海量数据的场景下,分布式运算. Map作一些,数据的局部处理和打散工作. Reduce作一些,数据的汇总工作. 这是之前的,weekend110的hdfs输入流之源 ...

  3. 编写简单的Mapreduce程序并部署在Hadoop2.2.0上运行

    今天主要来说说怎么在Hadoop2.2.0分布式上面运行写好的 Mapreduce 程序. 可以在eclipse写好程序,export或用fatjar打包成jar文件. 先给出这个程序所依赖的Mave ...

  4. Hadoop MapReduce概念学习系列之mr程序组件全貌(二十)

    其实啊,spilt是,控制Apache Hadoop Mapreduce的map并发任务数,详细见http://www.cnblogs.com/zlslch/p/5713652.html map,是m ...

  5. 用PHP编写Hadoop的MapReduce程序

    用PHP编写Hadoop的MapReduce程序     Hadoop流 虽然Hadoop是用Java写的,但是Hadoop提供了Hadoop流,Hadoop流提供一个API, 允许用户使用任何语言编 ...

  6. 一起学Hadoop——使用IDEA编写第一个MapReduce程序(Java和Python)

    上一篇我们学习了MapReduce的原理,今天我们使用代码来加深对MapReduce原理的理解. wordcount是Hadoop入门的经典例子,我们也不能免俗,也使用这个例子作为学习Hadoop的第 ...

  7. 编写一个基于HBase的MR程序,结果遇到一个错:ERROR security.UserGroupInformation - PriviledgedActionException as ,求帮助

    环境说明:Ubuntu12.04,使用CDH4.5,伪分布式环境 Hadoop配置如下: core-site.xml: <configuration><property>    ...

  8. Windows下Eclipse提交MR程序到HadoopCluster

    作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 欢迎转载,转载请注明出处. 以前Eclipse上写好的MapReduce项目经常是打好包上传到Hadoop测试集 ...

  9. 用python + hadoop streaming 编写分布式程序(一) -- 原理介绍,样例程序与本地调试

    相关随笔: Hadoop-1.0.4集群搭建笔记 用python + hadoop streaming 编写分布式程序(二) -- 在集群上运行与监控 用python + hadoop streami ...

随机推荐

  1. LindDotNetCore~ISoftDelete软删除接口

    回到目录 概念 ISoftDelete即软删除,数据在进行delete后不会从数据库清除,而只是标记一个状态,在业务范围里都不能获取到这个数据,这在ORM框架里还是比较容易实现的,对传统的ado来说需 ...

  2. debian The type initializer for 'System.Drawing.KnownColors' threw an exception

     Change the "System.Drawing" reference of "CoreCompat.System.Drawing"if you thro ...

  3. 机器学习之logistic回归算法与代码实现原理

    Logistic回归算法原理与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/10033567.html ...

  4. 玩转Spring Cloud之API网关(zuul)

    最近因为工作原因,一直没有空写文章,所以都是边忙项目,边利用空闲时间,周末时间学习总结,最终在下班回家后加班加点写完本篇文章,若有不足之处,还请谅解,谢谢! 本文内容导航: 一.网关的作用 二.网关与 ...

  5. Eureka的工作原理以及它与ZooKeeper的区别

    1.Eureka 简介: Eureka 是 Netflix 出品的用于实现服务注册和发现的工具. Spring Cloud 集成了 Eureka,并提供了开箱即用的支持.其中, Eureka 又可细分 ...

  6. c#实战开发:以太坊钱包快速同步区块和钱包卡死解决方案 (三)

    首先以太坊默认的快速同步模式 我们需要先设置当前同步模式内存大小512-2048范围 在服务器配置情况下最大化内存 输入以下命令 geth --fast --cache=2048 最快同步模式也是 保 ...

  7. Vue.js实现注册功能

    编写html,通过vue-resource.js库向后台提交数据 <!DOCTYPE html> <html lang="en"> <head> ...

  8. 前端入门23-CSS预处理器(Less&Sass)

    声明 本篇内容梳理自以下几个来源: Github:smyhvae/web Bootstrap网站的 less 文档 Sass中文网 感谢大佬们的分享. 正文-CSS预处理(less&Sass) ...

  9. 《JavaScript高级程序设计》笔记:BOM(八)

    BOM(浏览器对象模型)提供了很多对象,用于访问浏览器的功能,这些功能与任何网页内容无关. window对象 全局作用域 定义全局变量与在window对象上直接定义属性还是有一点差别:全局变量不能通过 ...

  10. 第十课html5 新增标签及属性 html5学习5

    一.常用新增标签 1.header:定义页面的页眉头部 2.nav:定义导航栏 3.footer:定义页面底部,页脚 4.article:定义文章 5.section:定义区域 6.aside:定义侧 ...