zoukankan      html  css  js  c++  java
  • MapFile检索序列文件

    1、MapFile写入文件

      /**
         * mapfile写入文件
         * @throws IOException
         */
        @Test
        public void save() throws IOException {
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", "file:///");
            FileSystem fs = FileSystem.get(conf);
            Path path = new Path("D:\sequence\1.seq");
            MapFile.Writer writer  = new MapFile.Writer(conf,fs,"d:/map",IntWritable.class,Text.class);
            for(int i = 0; i < 10; i++){
                writer.append(new IntWritable(i),new Text("hello" + i));
            }
            writer.close();
        }



    MapFile写入的时候产生两个文件,一个index序列索引文件,一个data数据序列文件
    index文件定义key的区间范围便于快速查找和定位

    2、MapFile读取文件

        /**
         * MapFile读取文件
         * @throws IOException
         */
        @Test
        public void read() throws IOException {
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", "file:///");
            FileSystem fs = FileSystem.get(conf);
            MapFile.Reader reader  = new MapFile.Reader(fs,"d:/map",conf);
            IntWritable key = new IntWritable();
            Text value = new Text();
            while (reader.next(key,value)){
                System.out.println(key.get() + "===>" + value.toString());
            }
        }


    欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
  • 相关阅读:
    存储过程与事务实现转账
    win7创建虚拟无线网络
    .net制作安装包 如何生成快捷方式
    安装EFCodeFirst失败。。。。
    用VS2010自带的Library Package Manager安装EFCodeFirst出现“无法加载一个或多个请求的类型”错误的解决方法
    Java struts2
    Java spring
    Java web
    传输层
    xml
  • 原文地址:https://www.cnblogs.com/flyingcr/p/10326971.html
Copyright © 2011-2022 走看看