sequence file(hadoop专设)
存的是key-value key-value key-value key-value key-value ---->不是字符串,是key-value 对象序列化之后的二进制,在文件最前面会存一些类的名称,
普通文本文件需要拿字符串切自己想要的东西, 而此文件可以直接读一对key-value ,中间环节产生的文件就可以用这种文件格式,下一个环节读的时候不用切和转类型,读出来就是key-value。
根据eleven day 中的需求:https://blog.csdn.net/ZJX103RLF/article/details/89059615
我拿这个为例 做一下中间环节生成的是sequence file
1、首先第一个mr程序还是读源文件,只是在job提交的时候将默认的生成文件类型变一下,其他不变
由job.setOutputFormatClass(TextOutputFormat.class); // 这是默认的输出组件
改为job.setOutputFormatClass(SequenceFileOutputFormat.class);生成SequenceFile
2、需要改一下mr程序的map方法读SequenceFile
public static class IndexStepTwoMapper extends Mapper<Text, IntWritable, Text, Text> {
@Override
protected void map(Text key, IntWritable value, Context context) throws IOException, InterruptedException {
String[] split = key.toString().split("-");
context.write(new Text(split[0]), new Text(split[1]+"-->"+value));
}
}
然后就是job提交的时候job.setInputFormatClass(TextInputFormat.class); 将默认的输入组件改为
job.setInputFormatClass(SequenceFileInputFormat.class);
finish。