HBASE学习笔记(三)

一、


   1.预切割:在创建表的时候,预先对表进行region切割。切割线就是rowkey

$hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40']
$hbase>create 'ns2:t3',SPLITS=>['row3000','row6000']  //创建表t3,并且进行预先切割
$hbase>desc 'ns2:t3'      //查看列族信息    
$hbase>scan 'hbase:meta'   //查看切片信息
$hbaes>put 'ns2:t3','row5000','f1:name','tom'  //向表中添加数据
$hbase>flush 'ns2:t3'        //从内存中清理数据到磁盘中去
$hbase>create 'ns2:t4',{NAME=>'f1',VERSIONS=>3}  //创建表的时候指定列族的版本数,同一个列族下的所有列具有相同的版本数
$hbase>put 'ns2:t4','row1','f1:name','tom'    //向表中添加元素
$hbase>put 'ns2:t4','row1','f1:name','tomas'  //向表中添加元素
$hbase>put 'ns2:t4','row1','f1:name','tomson'
$hbase>get 'ns2:t4','row1'    //我们刚插入了三个数据,但是我们get数据的时候只能看到一个数据,默认查询的时候只显示最新的数据
$hbase>get 'ns2:t4','row1',{COLUMN=>f1,VERSIONS=>3}  //查看最近3个版本的数据
$hbase>get 'ns2:t4','row1',{COLUMN=>f1,VERSION=>2}    //在进行查询的时候可以指定显示的版本数为2
$hbase>get 'ns2:t4','row1',{COLUMN=>'f1',TIMESTAMP=>1531882253591}

############################################接下来演示原生扫描######################################
$hbase>scan 'ns2:t4',{COLUMN=>'f1',RAW=>true,VERSIONS=>10}  //进行原生扫描,扫描的版本数为10,可以将所有的历史版本数的数据都扫描出来
$hbase>scan 'ns2:t4',{COLUMN=>'f1',TTL=>10,VERSIONS=>3}      //创建一个表,存活时间为10秒,版本数为3


  2.创建文件的时候进行预切割,结果如下图,查看WEBUI16010

  

  3.批量与缓存

    1)扫描器缓存,是面向行一级的

 @Test
    public void testScanCaching() throws Exception {
        Configuration conf =HBaseConfiguration.create();
        Connection conn = ConnectionFactory.createConnection(conf);
        TableName tname = TableName.valueOf("ns1:t1");
        Scan scan = new Scan();
        scan.setCaching(10000);
        System.out.println(scan.getCaching());
        Table table =conn.getTable(tname);
        ResultScanner rs = table.getScanner(scan);
        Iterator<Result> it= rs.iterator();
        long start= System.currentTimeMillis();
        while(it.hasNext()){
            Result r = it.next();
            System.out.println(r.getColumnLatestCell(Bytes.toBytes("f1"),Bytes.toBytes("name")));

        }
        System.out.println(System.currentTimeMillis()-start);
    }

  2)批量扫描是面向列一级的,批量可以让用户选择每次ResultScanner实例的next()操作要返回多少列。比如在扫描中设置setBatch(5),则一次next()返回的Result实例会包括5列

     scan.setBatch(5);//每次next()都返回5列

  

猜你喜欢

转载自www.cnblogs.com/bigdata-stone/p/9334086.html