Hadoop 0.20.205 Job(而不是JobConf)Bzip2压缩

时间:2011-12-14 10:10:52

标签: compression hadoop bzip2

在hadoop 0.20.2版本中,可以通过以下方式向jobconf添加输入/输出压缩:

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

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

不推荐使用jobConf,而应该使用job。如何在那里添加压缩/解压缩?特别是,如何更改wordcount示例以输入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);
}

2 个答案:

答案 0 :(得分:0)

提交作业时使用如下Configuration课程

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

答案 1 :(得分: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);