Hadoop detailed (ix) compression in MapReduce

Source: Internet
Author: User
Tags exit

As input

When the compressed file is MapReduce input, MapReduce will automatically extract the corresponding codec from the extension.

As output

When the MapReduce output file requires compression, you can change mapred.output.compress to True, Mapped.output.compression.codec the class name for the codec you want to use

Yes, of course you can specify in the code, by calling the Fileoutputformat static method to set these two properties, let's look at the code:

Package com.sweetop.styhadoop;  
Import Org.apache.hadoop.fs.Path;  
Import org.apache.hadoop.io.IntWritable;  
Import Org.apache.hadoop.io.Text;  
Import Org.apache.hadoop.io.compress.GzipCodec;  
Import Org.apache.hadoop.mapreduce.Job;  
Import Org.apache.hadoop.mapreduce.lib.input.FileInputFormat;  
      
Import Org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;  
      
Import java.io.IOException; 
 /** * Created with IntelliJ idea. * User:lastsweetop * date:13-6-27 * Time: PM 7:48 * To change this template use File | Settings | 
 File Templates.  
        */public class Maxtemperaturewithcompression {public static void main (string[] args) throws Exception {  
            if (args.length!=2) {System.out.println ("Usage:maxtemperature <input path> <out");  
        System.exit (-1);  
        Job Job=new job ();  
        Job.setjarbyclass (Maxtemperature.class);  
      
Job.setjobname ("Max temperature");        Fileinputformat.addinputpath (Job, New Path (args[0));  
      
        Fileoutputformat.setoutputpath (Job, New Path (args[1));  
        Job.setmapperclass (Maxtemperatruemapper.class);  
        Job.setcombinerclass (Maxtemperaturereducer.class);  
      
        Job.setreducerclass (Maxtemperaturereducer.class);  
        Job.setoutputkeyclass (Text.class);  
      
        Job.setoutputvalueclass (Intwritable.class);  
        Fileoutputformat.setcompressoutput (Job, true);  
      
        Fileoutputformat.setoutputcompressorclass (Job, Gzipcodec.class);  
      
    System.exit (Job.waitforcompletion (true)? 0:1); }  
}

Input is also a compressed file

~/hadoop/bin/hadoop com.sweetop.styhadoop.MaxTemperatureWithCompression input/data.gz output/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.