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的更多相关文章
随机推荐
- Partition Refinement
今天613问我怎么做DFA最小化..呃..这个我怎么可能会做呢.. 于是我就去学习了一点姿势,先把我Partition Refinement Data Structure的代码发上来好了.. 我挺菜的 ...
- Twitter如何在数千台服务器上快速部署代码?
答案是:用BT,也就是你我应该都很熟悉的BitTorrent. 对于网站经营者.创业者来说,扩展性的问题是在网站流量成长过程中势必会面对的问题,如何建立一个具有扩展性的架构(scalable arch ...
- 使用 swagger组件给asp.net webapi文档生成
1.名词解释 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模 ...
- 【CF1043B】Lost Array(枚举)
题意:给定n与数组a,求所有的k使得存在x数组能按以下规则构造出a n<=1e3,a[i]<=1e6 思路: #include<cstdio> #include<cstr ...
- Java中Collections的sort方法和Comparable与Comparator的比较
一.Comparable 新建Student1类,类实现Comparable接口,并重写compareTo方法 public class Student1 implements Comparable& ...
- 气象城市ID列表
气象城市ID列表 数据来源: http://cj.weather.com.cn/support/Detail.aspx?id=51837fba1b35fe0f8411b6df 记录了2574个地区,2 ...
- [LeetCode] Path Sum II 深度搜索
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- 高级参数绑定(数组和List绑定)
1.绑定数组: (1) 需求 在商品列表页面选中多个商品,然后删除. (2). 需求分析 功能要求商品列表页面中的每个商品前有一个checkbok,选中多个商品后点击删除按钮把商品id传递给Contr ...
- duilib入门简明教程 -- 自绘标题栏(5) (转)
原文转自 http://www.cnblogs.com/Alberl/p/3343667.html 如果大家有做过标题栏的自绘,肯定会感慨各种不容易,并且现有的一些资料虽然完美的实现了 ...
- python - break和continue
break 终止整个循环:当循环或判断执行到break语句时,即使判断条件为True或者序列尚未完全被历遍,都会跳出循环或判断 for i in xrange(10): print(i) if i = ...