【发布时间】:2013-05-03 07:01:33
【问题描述】:
如果可以选择,我会喜欢可以从 Hadoop shell 运行的东西而不是 MR 作业。我只有几个文件需要转换。
【问题讨论】:
如果可以选择,我会喜欢可以从 Hadoop shell 运行的东西而不是 MR 作业。我只有几个文件需要转换。
【问题讨论】:
一些未经测试但应该可以解决问题的代码(显然文件名是由组成的 - 序列文件通常没有扩展名):
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path inputPath = new Path("part-r-00000.snappy");
Path outputPath = new Path("part-r-00000.deflate");
FSDataOutputStream dos = fs.create(outputPath);
SequenceFile.Reader reader = new SequenceFile.Reader(fs, inputPath,
conf);
Writable key = (Writable) ReflectionUtils.newInstance(
reader.getKeyClass(), conf);
Writable value = (Writable) ReflectionUtils.newInstance(
reader.getValueClass(), conf);
CompressionCodecFactory ccf = new CompressionCodecFactory(conf);
CompressionCodec codec = ccf.getCodecByClassName(DefaultCodec.class
.getName());
SequenceFile.Writer writer = SequenceFile.createWriter(conf, dos,
key.getClass(), value.getClass(), reader.getCompressionType(),
codec);
while (reader.next(key, value)) {
writer.append(key, value);
}
reader.close();
dos.close();
您还应该通过 ToolRunner / Tool 模式获取配置 - 这是一个类似的问题,概述了它,以防它为您提供新的主体:
【讨论】: