HBASE学习笔记(三)
2024-09-02 09:24:35
一、
1.预切割:在创建表的时候,预先对表进行region切割。切割线就是rowkey
$hbase> create 't1', 'f1', SPLITS => ['', '', '', '']
$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();
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列
最新文章
- STM32环境搭建/学习观点/自学方法 入门必看
- PDO的一些操作
- Java处理Excel整理篇
- js根据className获取元素封装
- python基础整理笔记(二)
- php 分页类
- 《javascript高级程序设计》第21章 Ajax和Comet
- 业务gis 搭建一个skyline 的js模板 (一)
- 雪花降落CAEmitterLayer粒子效果
- netty-all maven中 缺少jzlib
- oracle删除字段中的空格、回车及指定字符
- hibernate flushMode 错误
- HttpClient4.2 Fluent API学习
- 简单使用WebSocket实现聊天室
- Linux 设置最大链接
- abstract class和interface有什么区别?
- 01:MongoDB基础
- vue-router2.0
- mysql日期时间函数使用总结
- 异常之交叉编译---arm-vfp-linux-gnu/bin/ld: cgic.o: Relocations in generic ELF (EM: 3)