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());
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值