2011-12-14 69 views
0

在Hadoop的0.20.2版本,可以輸入/輸出壓縮以下列方式添加到jobconf:的Hadoop 0.20.205工作(而不是JobConf)的bzip2壓縮

jobConf.setBoolean("mapred.output.compress", true); 

jobConf.setClass("mapred.output.compression.codec", BZip2Codec.class, CompressionCodec.class); 

jobConf已被廢棄,工作應該是改爲使用。我如何在那裏添加壓縮/解壓縮?特別是,我怎麼能在單詞計數改變。例如輸入的bzip2文件中:

public class WordCount { 
public static void main(String[] args) throws Exception { 
    Configuration conf = new Configuration(); 
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); 
    Job job = new Job(conf, "Example Hadoop 0.20.1 WordCount"); 
    job.setJarByClass(WordCount.class); 
    job.setMapperClass(TokenCounterMapper.class); 
    job.setReducerClass(TokenCounterReducer.class); 
    job.setOutputKeyClass(Text.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); 
} 

回答

0

使用Configuration類,如下,同時提交工作

Configuration conf = new Configuration(); 
conf.set("mapred.output.compression.codec", 
    "org.apache.hadoop.io.compress.BZip2Codec"); 
Job job = new Job(conf); 
0

這是我發現壓縮輸出方式:

Job job = new Job(conf, "FromToWordStatistics"); 
job.setJarByClass(FromToWordStatistics.class); 
job.setMapperClass(TokenizerMapper.class); 
job.setCombinerClass(IntSumReducer.class); 
job.setReducerClass(IntSumReducer.class); 
job.setOutputKeyClass(Text.class); 
job.setOutputValueClass(IntWritable.class); 
job.setCombinerClass(IntSumReducer.class); 
job.setNumReduceTasks(20); 

SequenceFileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); 
SequenceFileOutputFormat.setCompressOutput(job, true); 
SequenceFileOutputFormat.setOutputCompressorClass(job, BZip2Codec.class);