mapreduce_template
Hadoop Tutorial - YDN https://developer.yahoo.com/hadoop/tutorial/module4.html
import java.io.IOException;
import java.util.StringTokenizer; 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.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.GenericOptionsParser; public class test { public static class Map extends Mapper<Object, Text, Text, IntWritable>{ private IntWritable one = new IntWritable(1);
private Text word = new Text(); public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String inputValue=value.toString();//input
context.write(word, one);//output
}
} public static class Reduce extends Reducer<Text,IntWritable,Text,Text> { private Text result = new Text("reduce");
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
for (IntWritable val : values) {
val.get();//get number
val.toString();//get string
val.toString().getBytes();//get byte[]
}
context.write(key, result);
}
} public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: <in> <out>");
System.exit(2);
}
Job job = Job.getInstance(conf, "job name");
job.setJarByClass(test.class);
job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
mapreduce_template的更多相关文章
随机推荐
- Origin 2018 的坐标轴中文标签发生倒立/翻转
问题: 在使用 origin 2018 作图时,坐标轴或者是标签中输入中文后,将其更换中文字体(英文字体没有该问题)后发生倒立的情况 解决: 后来发现 Origin 2018 中存在两种中文字体,其中 ...
- 【BZOJ4402】Claris的剑(组合计数)
题意: 给定数列的定义: 1.每个元素都是正整数 2.每个元素不能超过M 3.相邻两个元素的差的绝对值必须是1 4.第一个元素的值必须是1 求有多少个长度不超过N的合法的本质不同的序列 两个序列本质不 ...
- Eclipse与MyEclipse修改注释字体颜色
修改配置路劲 Window--->Preferences--->Java--->Editor--->Syntax Coloring--->Element--->Co ...
- HTML title属性换行显示的方法
原文发布时间为:2009-04-22 -- 来源于本人的百度文章 [由搬家工具导入] 解决的方法有两种: 1.将title属性分成几行来写,例如:<a href=#" title=&q ...
- 远程连接linux和linux的网络配置
linux一般是作为服务器的,并不直接对其进行操作,并且由于地理位置的原因,我们需要对linux服务器进行远程连接. 首先我们要确定linux服务器是否安装了ssh服务,在linux服务器上安装ope ...
- [LeetCode] Add Two Numbers 链表
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- sokect数据压缩实现
上一篇文章说到了用Java Socket来传输对象,但是在有些情况下比如网络环境不好或者对象比较大的情况下需要把数据对象进行压缩然后在传输,此时就需要压缩这些对象流,此时就 可以GZIPInputSt ...
- 02深入理解C指针之---指针类型和值
该系列文章源于<深入理解C指针>的阅读与理解,由于本人的见识和知识的欠缺可能有误,还望大家批评指教. 1.指针的类型: 可以在声明指针时,指定指针的类型,例如: (1)void *x 声 ...
- TDictionary字典 记录 的赋值。
type TRen = record age: Integer; //把name定义成结构的属性. private Fname: string; procedure Setname(const Val ...
- 网站安全测试工具GoLismero
网站安全测试工具GoLismero GoLismero是一款开源的安全测试框架.目前,它的测试目标主要为网站.该框架采用插件模式,实现用户所需要的功能.GoLismero默认自带了导入.侦测.扫描.攻 ...