hadoop学习笔记之数据排序
来源:互联网 发布:阿里云服务器机房地址 编辑:程序博客网 时间:2024/06/05 04:28
package cn.yws;import java.io.IOException;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 MySort {public static class MyMap extends Mapper<Object, Text, IntWritable, IntWritable>{private static IntWritable data=new IntWritable();@Overrideprotected void map(Object key, Text value,org.apache.hadoop.mapreduce.Mapper.Context context)throws IOException, InterruptedException {String line=value.toString();data.set(Integer.parseInt(line));context.write(data, new IntWritable(1));//super.map(key, value, context);}}public static class MyReduce extends Reducer<IntWritable, IntWritable, IntWritable, IntWritable>{private static IntWritable linenum=new IntWritable();protected void reduce(IntWritable key, Iterable<IntWritable> values,org.apache.hadoop.mapreduce.Reducer.Context context)throws IOException, InterruptedException {//super.reduce(key, values, context);for(IntWritable val:values){context.write(linenum, key);linenum=new IntWritable(linenum.get()+1);}}}public static void main(String[] args) throws Exception {Configuration configuration=new Configuration();configuration.set("mapred.job.tracker", "192.168.1.9:9001");String[] ioArgs=new String[]{"sort_in","sort_out"};if(args.length==2){ioArgs=args;}String otherArgs[]=new GenericOptionsParser(configuration,ioArgs).getRemainingArgs();if(otherArgs.length!=2){System.err.println("Usage: Data MySort <in> <out>");System.exit(2);}Job job=new Job(configuration,"data sort");job.setJarByClass(MySort.class);job.setMapperClass(MyMap.class);job.setCombinerClass(MyReduce.class);job.setReducerClass(MyReduce.class);job.setOutputKeyClass(IntWritable.class);job.setOutputValueClass(IntWritable.class);FileInputFormat.addInputPath(job, new Path(otherArgs[0]));FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));System.exit(job.waitForCompletion(true)?0:1);}}
sort_in
12551224564125415279324584524641234545
0 0
- hadoop学习笔记之数据排序
- hadoop学习--数据排序
- hadoop学习--数据排序
- hadoop学习笔记之HiveSQL 数据查询
- 大数据之hadoop[MapReduce]学习 笔记
- 大数据学习笔记之二十七 Hadoop的HBase
- hadoop学习之数据复制
- hadoop学习之数据完整性
- Hadoop学习笔记之---Hadoop I/O
- Hadoop学习笔记之安装Hadoop
- Hadoop学习笔记之Hadoop简介
- Hadoop学习笔记之--Hadoop的安装
- Hadoop学习笔记之---HDFS
- hadoop学习笔记之wordcount
- hadoop学习笔记之grep
- hadoop学习之--Hive笔记
- Hadoop学习笔记之HDFS
- Hadoop学习笔记之RPC
- 根据结构体某个成员的地址求出结构体所有成员的值
- 中断处理体系结构
- jquery $.get $.post的区别
- 利用图像中物体轮廓做简单的图像匹配
- 一个简单的自动化测试报告
- hadoop学习笔记之数据排序
- usaco 4.4.2 Pollutant Control
- 杭电 1421 搬寝室
- 适用于kali linux的远程桌面开启方法(从windows xp 远程登录到kali linux )
- cocos2dx 多线程
- SeekBar的使用
- 软酷网 推IT课程免费在线学计划
- 使用静态成员处理时间类
- mysql 的 find_in_set函数使用方法