Hadoop 0.20.205 Job(而非 JobConf)Bzip2 压缩

发布于 2024-12-21 12:23:38 字数 1017 浏览 3 评论 0原文

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

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

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

jobConf 已弃用,应使用 job 代替。如何在那里添加压缩/解压缩?特别是,如何更改字数示例以输入 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);
}

In hadoop 0.20.2 version one can add input/output compression to the jobconf in the following way:

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

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

jobConf is deprecated and job should be used instead. How can I add compression/decompression there? In particular, how can I change the wordcount example to input bzip2 files:

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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清音悠歌 2024-12-28 12:23:38

使用 Configuration 类,如下所示提交作业

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

Use the Configuration class as below while submitting the Job

Configuration conf = new Configuration();
conf.set("mapred.output.compression.codec",
    "org.apache.hadoop.io.compress.BZip2Codec");
Job job = new Job(conf);
成熟稳重的好男人 2024-12-28 12:23:38

这是我发现压缩输出的方法:

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); 

This is the way I found to compress the output:

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); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文