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);
}
}

最新文章

  1. 数组 Arrays类
  2. 旧项目如何切换到Entity Framework Code First
  3. 几个与特殊字符处理有关的PHP函数
  4. Java [leetcode 10] Regular Expression Matching
  5. JuliaSet&amp;MandelBulb @ Maya&amp;KK —— 4亿粒子的测试
  6. android之获取应用中的图片资源_获取找你妹中的图片资源
  7. Kafka权威指南——broker的常用配置
  8. HTML 头标签的 &lt;title&gt; &lt;base&gt; &lt;meta&gt; &lt;link&gt; &lt;script&gt; 的内容意思
  9. python基础 列表 的用法及介绍
  10. 编写DAO,通过JdbcTemplate操作数据库的实践
  11. Java中常见数据结构Map之HashMap
  12. PDA(Windows Mobile)调用远程WebService
  13. SQL SERVER-创建Alwayson
  14. bzoj千题计划315:bzoj3172: [Tjoi2013]单词(AC自动机)
  15. docker被入侵后.............
  16. 多点触控 TouchAction
  17. VMware的快照和克隆总结
  18. CentOS下安装vsftpd
  19. LCA在线算法(hdu2586)
  20. Oracle 11g

热门文章

  1. linux压缩文件——解压方法
  2. Chrome 浏览器访问 Google 学术出现问题 “but your computer or network may be sending automated queries. ”
  3. 海拔(bzoj 2007)
  4. Codevs 1085 数字游戏
  5. 【HDOJ5973】Game of Taking Stones(Java,威佐夫博弈)
  6. 一个.java文件定义多个类的情况
  7. AC日记——[Sdoi2010]星际竞速 bzoj 1927
  8. 牛客网 Wannafly挑战赛8 B.LBJX的三角形
  9. codevs——1169 传纸条(棋盘DP)
  10. Xamarin XAML语言教程Xamarin.Forms中改变活动指示器颜色