Hbase之必要时取出请求的行(列族所有数据)
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CellScanner;
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; /**
* Created by similarface on 16/8/22.
*/
public class RetrievesRequestedRowNecessary {
public static void main(String args[]) throws IOException {
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
//建立表的连接
Table table = connection.getTable(TableName.valueOf("testtable")); //获取行键 企图获取一个不存在的行
Get get1 = new Get(Bytes.toBytes("95599"));
//添加查询的列族和列限定符号
get1.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"));
//获取结果级
Result result1 = table.get(get1);
//结果集是否为空 ==> Get 1 isEmpty: true
System.out.println("Get 1 isEmpty: " + result1.isEmpty());
//根据result获取游标
CellScanner scanner1 = result1.cellScanner();
//循环遍历结果集的数据 当然是没有任何数据
while (scanner1.advance()) {
System.out.println("Get 1 Cell: " + scanner1.current());
} //95599行键的值 数据库不存在这行数据
Get get2 = new Get(Bytes.toBytes("95599"));
//指定列族和列限定符
get2.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"));
//95599这行是在数据库中没有的 setClosestRowBefore 会试图去取前面的行如果有必要的话
get2.setClosestRowBefore(true);
//获取数据集 ==> Get 2 isEmpty: false
Result result2 = table.get(get2);
System.out.println("Get 2 isEmpty: " + result2.isEmpty());
//继续获取游标
CellScanner scanner2 = result2.cellScanner();
//遍历游标获取数据 ==> Get 2 Cell: 10086/colfam1:qual1/1471836722159/Put/vlen=12/seqid=0
while (scanner2.advance()) {
System.out.println("Get 2 Cell: " + scanner2.current());
} //这行数据库是存在的
Get get3 = new Get(Bytes.toBytes("10010"));
get3.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual2"));
//依然+了setClosestRowBefore
get3.setClosestRowBefore(true);
// ==> Get 3 isEmpty: false
Result result3 = table.get(get3);
System.out.println("Get 3 isEmpty: " + result3.isEmpty());
CellScanner scanner3 = result3.cellScanner();
//如果存在行还是取出的该行的数据
while (scanner3.advance()) {
//叫了setClosestRowBefore 的作用在这儿是请求列族中的所有列分隔的字段都要取出来
// Get 3 Cell: 10010/colfam1:qual1/1471836722159/Put/vlen=12/seqid=0
// Get 3 Cell: 10010/colfam1:qual2/1471836722159/Put/vlen=18/seqid=0
System.out.println("Get 3 Cell: " + scanner3.current());
} Get get4 = new Get(Bytes.toBytes("10086"));
get4.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"));
//Get 4 isEmpty: false
Result result4 = table.get(get4);
System.out.println("Get 4 isEmpty: " + result4.isEmpty());
CellScanner scanner4 = result4.cellScanner();
while (scanner4.advance()) {
//Get 4 Cell: 10086/colfam1:qual1/1471836722159/Put/vlen=12/seqid=0
System.out.println("Get 4 Cell: " + scanner4.current());
}
}
}
/**
Get 1 isEmpty: false
Get 1 Cell: 10086/colfam1:qual1/1471836722159/Put/vlen=12/seqid=0
Get 2 isEmpty: false
Get 2 Cell: 10086/colfam1:qual1/1471836722159/Put/vlen=12/seqid=0
Get 3 isEmpty: false
Get 3 Cell: 10010/colfam1:qual1/1471836722159/Put/vlen=12/seqid=0
Get 3 Cell: 10010/colfam1:qual2/1471836722159/Put/vlen=18/seqid=0
Get 4 isEmpty: false
Get 4 Cell: 10086/colfam1:qual1/1471836722159/Put/vlen=12/seqid=0 **/
Hbase之必要时取出请求的行(列族所有数据)的更多相关文章
- Hbase之尝试使用错误列族获取数据
import com.google.common.base.Strings; import org.apache.hadoop.conf.Configuration; import org.apach ...
- 为什么不建议在 HBase 中使用过多的列族
我们知道,一张 HBase 表包含一个或多个列族.HBase 的官方文档中关于 HBase 表的列族的个数有两处描述: A typical schema has between 1 and 3 col ...
- 深入学习hbase:表,列族,列标识,版本和cell
HBase是面向列的分布式的数据库,和传统的关系型数据库有很大的不同:物理模型和逻辑模型.这里我们要首先讲一下HBase数据库相关的区别于关系型数据库的几个基本概念: 表:HBase ...
- HBase的java操作,最新API。(查询指定行、列、插入数据等)
关于HBase环境搭建和HBase的原理架构,请见笔者相关博客. 1.HBase对java有着较优秀的支持,本文将介绍如何使用java操作Hbase. 首先是pom依赖: <dependency ...
- HBase列族高级配置
转自:http://blog.sina.com.cn/s/blog_ae33b83901018euz.html ------------------ HBase有几个高级特性,在你设计表时可以使用.这 ...
- HBASE列族不能太多的真相 (一个table有几个列族就有几个 Store)
HRegionServer内部管理了一系列HRegion对象,每个HRegion对 应了table中的一个region,HRegion中由多 个HStore组成.每个HStore对应了Table中的一 ...
- HBase最佳实践-列族设计优化
本文转自hbase.收藏学习下. 随着大数据的越来越普及,HBase也变得越来越流行.会用HBase现在已经变的并不困难,然而,怎么把它用的更好却并不简单.那怎么定义'用的好'呢?很简单,在保证系统稳 ...
- 数据源、数据集、同步任务、数据仓库、元数据、数据目录、主题、来源系统、标签、增量识别字段、修改同步、ES索引、HBase列族、元数据同步、
数据源.数据集.同步任务.数据仓库.元数据.数据目录.主题.来源系统.标签. 增量识别字段.修改同步.ES索引.HBase列族.元数据同步.DS.ODS.DW.DM.zk集群地址 == 数据源 数据源 ...
- hbase源码系列(四)数据模型-表定义和列族定义的具体含义
hbase是一个KeyValue型的数据库,在<hbase实战>描述它的逻辑模型[行键,列族,列限定符,时间版本],物理模型是基于列族的.但实际情况是啥?还是上点代码吧. HTableDe ...
随机推荐
- python-day7 python内置模块 面向对象
1.configparser模块 configparser用于处理特定格式的文件,其本质上是利用open来操作文件 # 注释1 ; 注释2 [section1] # 节点 k1 = v1 # 值 k2 ...
- JAVA基础知识之JVM-——URLClassLoader
URLClassLoader是ClassLoader的一个实现类,它既能从本地加载二进制文件类,也可以从远程加载类. 它有两个构造函数, 即 URLClassLoader(URL[] urls),使用 ...
- ThreadLocal深入理解一
转载:http://www.cnblogs.com/dolphin0520/p/3920407.html 想必很多朋友对ThreadLocal并不陌生,今天我们就来一起探讨下ThreadLocal的使 ...
- jquery的ajax向ashx传值,中文乱码问题
从网上查找了很多资料: 有在配置文件里面加如下配置 <globalization responseEncoding="utf-8" requestEncoding=" ...
- File.separator
摘自:http://blog.csdn.net/chindroid/article/details/7735832
- 将XML文件中的内容转换为Json对象
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;u ...
- 八、java集合类
与数组的区别: 数组的长度是固定的,集合的长度是可变的.数组用来存放基本类型的数据,集合用来存放对象的引用. 1.集合类接口的常用方法 COllection接口是层次结构中的根接口,该接口提供了添加和 ...
- iOS 关于使用xib创建cell的两种初始化方式
[转]http://my.oschina.net/CgShare/blog/337406 方法一: 第一步: [self.collectionView registerNib:[UINib nibWi ...
- RTP学习笔记
一.定义 实时传输协议(Real- time Transport Protocol,RTP)是在Internet上处理多媒体数据流的一种网络协议,利用它能够在一对一(unicast,单播)或者一对多 ...
- 关于MySQL数据库如何按时间查询
这里做了几个测试 select * from simingpai where TIMESTAMP(createTime) >= '2015-9-6'; select * from simingp ...