我是靠谱客的博主 含糊羊,这篇文章主要介绍java outputformat,Java TextOutputFormat.setCompressOutput方法代码示例,现在分享给大家,希望可以做个参考。

import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; //导入方法依赖的package包/类

/**

* @param inputs

* the input paths to be expected

* @param output

* the output location

* @param conf

* the job configuration

* @return the job to be launched in this stage

* @throws Exception

* @throws IOException

*/

public Job stage(Path[] inputs, Path output, Configuration conf) throws Exception {

final Job job = new Job(conf);

// A bit of a dirty hack, if any input file is an lzo file sneakily

// switch the input format class to LZOTextInput

if (inputFormatClass.equals(TextInputFormat.class) && containsLZO(inputs)) {

job.setInputFormatClass((Class extends InputFormat, ?>>) Class

.forName("com.hadoop.mapreduce.LzoTextInputFormat"));

}

else {

job.setInputFormatClass(inputFormatClass);

}

job.setMapOutputKeyClass(mapOutputKeyClass);

job.setMapOutputValueClass(mapOutputValueClass);

job.setOutputKeyClass(outputKeyClass);

job.setOutputValueClass(outputValueClass);

job.setOutputFormatClass(outputFormatClass);

if (outputFormatClass.equals(TextOutputFormat.class) && this.lzoCompress()) {

TextOutputFormat.setCompressOutput(job, true);

TextOutputFormat.setOutputCompressorClass(job,

(Class extends CompressionCodec>) Class.forName("com.hadoop.compression.lzo.LzopCodec"));

} else {

TextOutputFormat.setCompressOutput(job, false);

}

job.setJarByClass(this.getClass());

setInputPaths(job, inputs);

setOutputPath(job, output);

setMapperClass(job, mapper());

setReducerClass(job, reducer());

setCombinerClass(job, combiner());

setup(job);

return job;

}

最后

以上就是含糊羊最近收集整理的关于java outputformat,Java TextOutputFormat.setCompressOutput方法代码示例的全部内容,更多相关java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部