mapreduce_template
2024-09-29 19:14:40
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);
}
}
最新文章
- 数组 Arrays类
- 旧项目如何切换到Entity Framework Code First
- 几个与特殊字符处理有关的PHP函数
- Java [leetcode 10] Regular Expression Matching
- JuliaSet&;MandelBulb @ Maya&;KK —— 4亿粒子的测试
- android之获取应用中的图片资源_获取找你妹中的图片资源
- Kafka权威指南——broker的常用配置
- HTML 头标签的 <;title>; <;base>; <;meta>; <;link>; <;script>; 的内容意思
- python基础 列表 的用法及介绍
- 编写DAO,通过JdbcTemplate操作数据库的实践
- Java中常见数据结构Map之HashMap
- PDA(Windows Mobile)调用远程WebService
- SQL SERVER-创建Alwayson
- bzoj千题计划315:bzoj3172: [Tjoi2013]单词(AC自动机)
- docker被入侵后.............
- 多点触控 TouchAction
- VMware的快照和克隆总结
- CentOS下安装vsftpd
- LCA在线算法(hdu2586)
- Oracle 11g
热门文章
- linux压缩文件——解压方法
- Chrome 浏览器访问 Google 学术出现问题 “but your computer or network may be sending automated queries. ”
- 海拔(bzoj 2007)
- Codevs 1085 数字游戏
- 【HDOJ5973】Game of Taking Stones(Java,威佐夫博弈)
- 一个.java文件定义多个类的情况
- AC日记——[Sdoi2010]星际竞速 bzoj 1927
- 牛客网 Wannafly挑战赛8 B.LBJX的三角形
- codevs——1169 传纸条(棋盘DP)
- Xamarin XAML语言教程Xamarin.Forms中改变活动指示器颜色