Hbase遍历方式
来源:互联网 发布:美编软件 编辑:程序博客网 时间:2024/06/07 06:07
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
/**
* 遍历获取数据
*/
public class ScanAccessData {
public static void main(String[] args) throws IOException {
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
//建立表的连接
Table table = connection.getTable(TableName.valueOf("testtable"));
//创建一个空的Scan实例
Scan scan1 = new Scan();
//在行上获取遍历器
ResultScanner scanner1 = table.getScanner(scan1);
//打印行的值
for (Result res : scanner1) {
System.out.println(res);
}
//关闭释放资源
scanner1.close();
Scan scan2 = new Scan();
//添加限定列族
scan2.addFamily(Bytes.toBytes("colfam1"));
ResultScanner scanner2 = table.getScanner(scan2);
for (Result res : scanner2) {
System.out.println(res);
}
scanner2.close();
Scan scan3 = new Scan();
//添加限定列族 列分隔 行偏移
scan3.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-5")).
addColumn(Bytes.toBytes("colfam2"), Bytes.toBytes("col-33")).
setStartRow(Bytes.toBytes("row-10")).
setStopRow(Bytes.toBytes("row-20"));
ResultScanner scanner3 = table.getScanner(scan3);
for (Result res : scanner3) {
System.out.println(res);
}
scanner3.close();
Scan scan4 = new Scan();
scan4.addColumn(Bytes.toBytes("colfam1"),
Bytes.toBytes("col-5")).
setStartRow(Bytes.toBytes("row-10")).
setStopRow(Bytes.toBytes("row-20"));
ResultScanner scanner4 = table.getScanner(scan4);
for (Result res : scanner4) {
System.out.println(res);
}
scanner4.close();
Scan scan5 = new Scan();
//添加倒序
scan5.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-5")).
setStartRow(Bytes.toBytes("row-20")).
setStopRow(Bytes.toBytes("row-10")).
setReversed(true);
ResultScanner scanner5 = table.getScanner(scan5);
for (Result res : scanner5) {
System.out.println(res);
}
scanner5.close();
}
}
阅读全文
0 0
- Hbase遍历方式
- Hbase 0.96后Result对象遍历方式
- hbase 读写遍历,java实现Hbase中的查询:Filter方式
- hbase 读写遍历
- Hbase 备份的方式
- HBase安装方式
- hbase数据迁移方式
- Hbase的访问方式
- HBase数据导入方式
- hbase 新版本 java api 遍历
- Hbase之遍历获取数据
- 遍历hbase中表的方法
- Hbase访问方式之Hbase shell
- Hbase访问方式之Hbase shell
- HBase管理 HBase数据备份方式对比
- Hbase访问方式之Hbase shell
- Hbase访问方式之Mapreduce
- Hbase访问方式之Mapreduce
- hbase 源代码解析(23)truncate 和truncate_preserve流程分析
- lua解决八皇后问题
- Linux系统网卡名称固化
- 实验三、链队列和顺序队列
- Git简介
- Hbase遍历方式
- 171024—函数自学【知识点初识】
- C++如何在.h头文件中直接定义函数
- 来自Java老师上课实例
- 15Python中的面向对象
- 通过db.properties文件的存放位置谈java项目及Web项目的路径问题
- 使用Bootstrap和Vue实现用户信息的编辑
- Linux系统磁盘监控邮件告警
- 16Python中的正则表达式