zoukankan      html  css  js  c++  java
  • mapreduce对一维的数组进行排序

    import java.io.IOException;
    
    
    import org.apache.hadoop.io.IntWritable;
    import org.apache.hadoop.io.LongWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapred.MapReduceBase;
    import org.apache.hadoop.mapred.Mapper;
    import org.apache.hadoop.mapred.OutputCollector;
    import org.apache.hadoop.mapred.Reporter;
    
    
    public class SortMapper extends MapReduceBase implements Mapper<LongWritable, Text, IntWritable,Text> {
    
    	@Override
    	public void map(LongWritable key, Text value, OutputCollector<IntWritable,Text> output,
    			Reporter reporter) throws IOException {
    		// TODO Auto-generated method stub
    		
    		String line=value.toString();
    		System.out.println(line);
    		output.collect(new IntWritable(Integer.parseInt(line)),new Text());
    		
    	}
    
    }
    import java.io.IOException;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IntWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapred.FileInputFormat;
    import org.apache.hadoop.mapred.FileOutputFormat;
    import org.apache.hadoop.mapred.JobClient;
    import org.apache.hadoop.mapred.JobConf;
    
    
    public class Sort {
    
    	/**
    	 * @param args
    	 * @throws IOException 
    	 */
    	public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
    		if(args.length!=2){
    			System.out.println("ge shi cuowu");
    			System.exit(-1);
    		}
    		
    		JobConf conf=new JobConf(Sort.class);
    		
    		conf.setJobName("Sort Test");
    		
    		
    		FileInputFormat.setInputPaths(conf, new Path(args[0]));
    		//FileOutputFormat.setCompressOutput(conf, true);
    		FileOutputFormat.setOutputPath(conf, new Path(args[1]));
    		conf.setMapperClass(SortMapper.class);
    		//conf.setOutputKeyClass(Text.class);
    		//conf.setOutputValueClass(IntWritable.class);
    		conf.setMapOutputKeyClass(IntWritable.class);
    		conf.setMapOutputValueClass(Text.class);
    		
    		JobClient.runJob(conf);
    
    	}
    
    }
    
  • 相关阅读:
    递归的小实例
    try-catch-finally实例
    集合的排序(正序,倒序,从大到小排序)
    数组的排序(sort和冒泡)
    拦截器的使用,不登录用户不能进行其他操作
    把日志从数据库导出到Excel表格中(poi)
    Java 对Excel进行导入操作
    java 面试题集锦
    端口被占用解决办法
    (转)Java 最常见的 200+ 面试题汇总
  • 原文地址:https://www.cnblogs.com/dlutxm/p/2145887.html
Copyright © 2011-2022 走看看