gpt4 book ai didi

hadoop - ZipFileOutputFormat不提供.zip格式的输出mapreduce

转载 作者:行者123 更新时间:2023-12-02 21:04:02 24 4
gpt4 key购买 nike

我有一个应用程序,可以读取HBase并将记录写入文件。
最终输出应为.zip压缩格式,而不是hadoop支持的格式。
为此,我使用了自定义ZipFileOutputFormat来获取.zip文件中的记录。

这是我的实现

ZipFileOutputFormat.setOutputPath(job, new Path(args[1]));

这是ZipFileOutputFormat.class的详细信息
public class ZipFileOutputFormat extends FileOutputFormat<NullWritable, Text> {
@Override
public RecordWriter<NullWritable, Text> getRecordWriter(
TaskAttemptContext job) throws IOException, InterruptedException {
Path file = getDefaultWorkFile(job, ".zip");

FileSystem fs = file.getFileSystem(job.getConfiguration());

return new ZipRecordWriter(fs.create(file, false));
}

public static class ZipRecordWriter extends
RecordWriter<NullWritable, Text> {
protected ZipOutputStream zos;

public ZipRecordWriter(FSDataOutputStream os) {
zos = new ZipOutputStream(os);
}

@Override
public void write(NullWritable key, Text value) throws IOException,
InterruptedException {
// TODO: create new ZipEntry & add to the ZipOutputStream (zos)
}

@Override
public void close(TaskAttemptContext context) throws IOException,
InterruptedException {
zos.close();
}
}
}

我没有收到任何错误,但是我的输出仍然是r-000001格式。

我在这里缺少任何配置吗?

最佳答案

我发现了问题。
在工作 session 中设置以下内容后,我的问题已消除

LazyOutputFormat.setOutputFormatClass(job, ZipFileOutputFormat.class);

在此之前
LazyOutputFormat.setOutputFormatClass(job, TextInputFormat.class);

也设置
job.setOutputFormatClass(ZipFileOutputFormat.class);

关于hadoop - ZipFileOutputFormat不提供.zip格式的输出mapreduce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42478922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com