有效利用 Map-Reduce 作业Hadoop http://hadoop.apache.org/,我需要将数据存储在hadoop的序列文件格式 http://hadoop.apache.org/common/docs/current/api/org/apache/hadoop/io/SequenceFile.html。但是,目前数据仅采用平面 .txt 格式。任何人都可以建议一种将 .txt 文件转换为序列文件的方法吗?
因此,更简单的答案就是一个具有 SequenceFile 输出的“身份”作业。
在java中看起来像这样:
public static void main(String[] args) throws IOException,
InterruptedException, ClassNotFoundException {
Configuration conf = new Configuration();
Job job = new Job(conf);
job.setJobName("Convert Text");
job.setJarByClass(Mapper.class);
job.setMapperClass(Mapper.class);
job.setReducerClass(Reducer.class);
// increase if you need sorting or a special number of files
job.setNumReduceTasks(0);
job.setOutputKeyClass(LongWritable.class);
job.setOutputValueClass(Text.class);
job.setOutputFormatClass(SequenceFileOutputFormat.class);
job.setInputFormatClass(TextInputFormat.class);
TextInputFormat.addInputPath(job, new Path("/lol"));
SequenceFileOutputFormat.setOutputPath(job, new Path("/lolz"));
// submit and wait for completion
job.waitForCompletion(true);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)