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的更多相关文章

随机推荐

  1. 基于Linux的嵌入式文件系统构建与设计

    摘 要:Linux是当今一种十分流行的嵌入式操作系统.由于其具有执行效率高.占用空间小.实时性能优良和可扩展性强等特点,因此被广泛应用于工业控制领域.该文对其文件系统进行了简单的介绍,结合嵌入式系统应 ...

  2. 星际竞速(bzoj 1927)

    Description 10年一度的银河系赛车大赛又要开始了.作为全银河最盛大的活动之一,夺得这个项目的冠军无疑是很多人的梦想,来自杰森座α星的悠悠也是其中之一.赛车大赛的赛场由N颗行星和M条双向星际 ...

  3. iPhone深度学习-ARM

    平台 xCode 5.0 iPhone 4 在Building setting中的 Architectures 部分,有这么一个选项 Architectures,这里有一些选项是 Armv7 和Arm ...

  4. 如何在Linux的桌面上创建快捷方式或启动器

    如果在Linux桌面系统中你经常使用一个程序,你可能想去创建一个“桌面快捷方式”,以便于你在桌面只要点击一下快捷方式就可以启动它.虽然不少带有图形界面的程序会在安装时自动在桌面上创建快捷方式,还有一些 ...

  5. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---57

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  6. gpio 預設值

    若 gpio 預設值只寫 pull-down or pull-up or no-pull or keeper, 代表 是 input mode.

  7. alloc_chrdev_region申请一个动态主设备号,并申请一系列次设备号

    ret = alloc_chrdev_region(&ndev, 0, 1, "chr_dev"); //分配设备号 alloc_chrdev_region申请一个动态主设 ...

  8. hdu 5698(杨辉三角的性质+逆元)

    ---恢复内容开始--- 瞬间移动 Accepts: 1018 Submissions: 3620 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...

  9. Android 中利用ViewFlipper 滑动屏幕切换页面,ListView展示数据

    首先新建一个Android项目,命名为ViewFlipperTest 如图:项目机构,本项目主要操作图中红色箭头标注的文件 1.HgroupAdapter.java文件代码↓主要实现listview数 ...

  10. ConstraintLayout 约束布局

    约束布局ConstraintLayout 这种布局方式出现已经有一段时间了,刚出现的时候一直以为这种布局只是针对拖拽使用的布局,最近在新项目里看到了这种布局,又重新学习了这种布局,才发现以前真的是图样 ...