How to convert .txt file to Hadoop#39;s sequence file format(如何将 .txt 文件转换为 Hadoop 的序列文件格式)
问题描述
为了有效利用 Hadoop 中的 map-reduce 作业,我需要将数据存储在 hadoop的序列文件格式.但是,目前数据只有平面 .txt 格式.谁能建议我可以将 .txt 文件转换为序列文件的方法?
To effectively utilise map-reduce jobs in Hadoop, i need data to be stored in hadoop's sequence file format. However,currently the data is only in flat .txt format.Can anyone suggest a way i can convert a .txt file to a sequence file?
推荐答案
所以更简单的答案就是一个具有 SequenceFile 输出的身份"作业.
在java中看起来像这样:
So the way more simplest answer is just an "identity" job that has a SequenceFile output.
Looks like this in 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);
   }
                        这篇关于如何将 .txt 文件转换为 Hadoop 的序列文件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 .txt 文件转换为 Hadoop 的序列文件格式
				
        
 
            
        基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
 - RabbitMQ:消息保持“未确认"; 2022-01-01
 - 如何对 Java Hashmap 中的值求和 2022-01-01
 - REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
 - Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
 - Struts2 URL 无法访问 2022-01-01
 - 使用堆栈算法进行括号/括号匹配 2022-01-01
 - 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
 - 存储 20 位数字的数据类型 2022-01-01
 - 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				