mapreduce读取sequencefile文件中的数据
来源:互联网 发布:网络电影所爱非人结局 编辑:程序博客网 时间:2024/06/03 03:11
- sequencefile中的数据是以key,value对存储的。
- 通过mapreduce模式,可以读取sequencefile中的数据。
- public class MapReduceReadFile {
- private static SequenceFile.Reader reader = null;
- private static Configuration conf = new Configuration();
- public static class ReadFileMapper extends
- Mapper<LongWritable, Text, LongWritable, Text> {
- /* (non-Javadoc)
- * @see org.apache.hadoop.mapreduce.Mapper#map(KEYIN, VALUEIN, org.apache.hadoop.mapreduce.Mapper.Context)
- */
- @Override
- public void map(LongWritable key, Text value, Context context) {
- key = (LongWritable) ReflectionUtils.newInstance(
- reader.getKeyClass(), conf);
- value = (Text) ReflectionUtils.newInstance(
- reader.getValueClass(), conf);
- try {
- while (reader.next(key, value)) {
- System.out.printf("%s\t%s\n", key, value);
- context.write(key, value);
- }
- } catch (IOException e1) {
- e1.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * @param args
- * @throws IOException
- * @throws InterruptedException
- * @throws ClassNotFoundException
- */
- public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
- Job job = new Job(conf,"read seq file");
- job.setJarByClass(MapReduceReadFile.class);
- job.setMapperClass(ReadFileMapper.class);
- job.setMapOutputValueClass(Text.class);
- Path path = new Path("logfile2");
- FileSystem fs = FileSystem.get(conf);
- reader = new SequenceFile.Reader(fs, path, conf);
- FileInputFormat.addInputPath(job, path);
- FileOutputFormat.setOutputPath(job, new Path("result"));
- System.exit(job.waitForCompletion(true)?0:1);
- }
0 0
- mapreduce读取sequencefile文件中的数据
- mapreduce读取sequencefile文件中的数据
- mapreduce读取sequencefile文件中的数据
- MapReduce读取sequencefile文件
- 自定义流读取内存中的SequenceFIle数据
- 使用MapReduce读取SequenceFile文件,批量导入HBase
- MapReduce中的SequenceFile和MapFile
- mapreduce中的sequenceFile类,MapFile解析
- mapreduce合并小文件成sequencefile
- MapReduce之普通文件转SequenceFile
- MapReduce之SequenceFile转普通文件
- Hadoop读取sequencefile和textfile文件内容
- sequencefile 由hdfs 上读取文件
- Hadoop Core 学习笔记(一) SequenceFile文件写入和读取Writable数据
- Hadoop Core 学习笔记(一) SequenceFile文件写入和读取Writable数据
- 读取文件中的数据
- hadoop中的文件接口类-- SequenceFile
- SequenceFile文件
- 20150108Review
- jpa对表的crud
- 遍历
- JDK+MyEclipse+Tomcat的配置
- 使用uiautomator做UI测试
- mapreduce读取sequencefile文件中的数据
- c++ string类的基本构造函数以及对象初始化实例
- 年轻时应养成的好习惯
- 雷观(十九):我的人生观
- PHP实例五之PHP+MYSQL留言板
- 计算机中整数加法满足结合律吗
- Android利用资源名称获取其ID
- 交换两个数字最好的方法 C
- 什么是HTML?