mapreduce中的压缩

转载请注明出处:http://blog.csdn.net/lastsweetop/article/details/9187721

作为输入

当压缩文件做为mapreduce的输入时,mapreduce将自动通过扩展名找到相应的codec对其解压。

作为输出

当mapreduce的输出文件需要压缩时,可以更改mapred.output.compress为true, mapped.output.compression.codec为想要使用的codec的类名就
可以了,当然你可以在代码中指定, 通过调用FileOutputFormat的静态方法去设置这两个属性,我们来看代码:
[java]  view plain copy
  1. package com.sweetop.styhadoop;  
  2.   
  3. import org.apache.hadoop.fs.Path;  
  4. import org.apache.hadoop.io.IntWritable;  
  5. import org.apache.hadoop.io.Text;  
  6. import org.apache.hadoop.io.compress.GzipCodec;  
  7. import org.apache.hadoop.mapreduce.Job;  
  8. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;  
  9. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;  
  10.   
  11. import java.io.IOException;  
  12.   
  13. /** 
  14.  * Created with IntelliJ IDEA. 
  15.  * User: lastsweetop 
  16.  * Date: 16-6-27 
  17.  * Time: 下午7:48 
  18.  * To change this template use File | Settings | File Templates. 
  19.  */  
  20. public class MaxTemperatureWithCompression {  
  21.     public static void main(String[] args) throws Exception {  
  22.         if (args.length!=2){  
  23.             System.out.println("Usage: MaxTemperature <input path> <out path>");  
  24.             System.exit(-1);  
  25.         }  
  26.         Job job=new Job();  
  27.         job.setJarByClass(MaxTemperature.class);  
  28.         job.setJobName("Max Temperature");  
  29.   
  30.         FileInputFormat.addInputPath(job, new Path(args[0]));  
  31.         FileOutputFormat.setOutputPath(job, new Path(args[1]));  
  32.   
  33.         job.setMapperClass(MaxTemperatrueMapper.class);  
  34.         job.setCombinerClass(MaxTemperatureReducer.class);  
  35.         job.setReducerClass(MaxTemperatureReducer.class);  
  36.   
  37.         job.setOutputKeyClass(Text.class);  
  38.         job.setOutputValueClass(IntWritable.class);  
  39.   
  40.         FileOutputFormat.setCompressOutput(job, true);  
  41.         FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);  
  42.   
  43.         System.exit(job.waitForCompletion(true)?0:1);  
  44.   
  45.     }  
  46. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值