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之必要时取出请求的行(列族所有数据)的更多相关文章

  1. Hbase之尝试使用错误列族获取数据

    import com.google.common.base.Strings; import org.apache.hadoop.conf.Configuration; import org.apach ...

  2. 为什么不建议在 HBase 中使用过多的列族

    我们知道,一张 HBase 表包含一个或多个列族.HBase 的官方文档中关于 HBase 表的列族的个数有两处描述: A typical schema has between 1 and 3 col ...

  3. 深入学习hbase:表,列族,列标识,版本和cell

    HBase是面向列的分布式的数据库,和传统的关系型数据库有很大的不同:物理模型和逻辑模型.这里我们要首先讲一下HBase数据库相关的区别于关系型数据库的几个基本概念:          表:HBase ...

  4. HBase的java操作,最新API。(查询指定行、列、插入数据等)

    关于HBase环境搭建和HBase的原理架构,请见笔者相关博客. 1.HBase对java有着较优秀的支持,本文将介绍如何使用java操作Hbase. 首先是pom依赖: <dependency ...

  5. HBase列族高级配置

    转自:http://blog.sina.com.cn/s/blog_ae33b83901018euz.html ------------------ HBase有几个高级特性,在你设计表时可以使用.这 ...

  6. HBASE列族不能太多的真相 (一个table有几个列族就有几个 Store)

    HRegionServer内部管理了一系列HRegion对象,每个HRegion对 应了table中的一个region,HRegion中由多 个HStore组成.每个HStore对应了Table中的一 ...

  7. HBase最佳实践-列族设计优化

    本文转自hbase.收藏学习下. 随着大数据的越来越普及,HBase也变得越来越流行.会用HBase现在已经变的并不困难,然而,怎么把它用的更好却并不简单.那怎么定义'用的好'呢?很简单,在保证系统稳 ...

  8. 数据源、数据集、同步任务、数据仓库、元数据、数据目录、主题、来源系统、标签、增量识别字段、修改同步、ES索引、HBase列族、元数据同步、

    数据源.数据集.同步任务.数据仓库.元数据.数据目录.主题.来源系统.标签. 增量识别字段.修改同步.ES索引.HBase列族.元数据同步.DS.ODS.DW.DM.zk集群地址 == 数据源 数据源 ...

  9. hbase源码系列(四)数据模型-表定义和列族定义的具体含义

    hbase是一个KeyValue型的数据库,在<hbase实战>描述它的逻辑模型[行键,列族,列限定符,时间版本],物理模型是基于列族的.但实际情况是啥?还是上点代码吧. HTableDe ...

随机推荐

  1. JAVA基础知识之JVM-——URLClassLoader

    URLClassLoader是ClassLoader的一个实现类,它既能从本地加载二进制文件类,也可以从远程加载类. 它有两个构造函数, 即 URLClassLoader(URL[] urls),使用 ...

  2. ThreadLocal深入理解二

    转载:http://doc00.com/doc/101101jf6 今天在看之前转载的博客:ThreadLocal的内部实现原理.突然有个疑问, 按照threadLocal的原理, 当把一个对象存入到 ...

  3. SharePoint API测试系列——对Recorded Item做OM操作(委托的妙用)

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 对Recorded Item动态调用OM Methods进行测试,界面如下: 输入Site的URL ...

  4. torch基本命令

    命令行输入th进入torch框架 命令行输入th + lua文件表示用torch执行lua文件

  5. 表结构导出到excel中

    SELECT 表名 = case when a.colorder=1 then d.name else '' end, 表说明 = case when a.colorder=1 then isnull ...

  6. KDTree

    学习链接:http://www.cnblogs.com/eyeszjwang/articles/2429382.html 下面实现的kdtree支持以下操作:(1) 插入一个节点(2) 插入n个节点( ...

  7. Devexpress TreeList选择父级联动

    Treelist当显示复选框后,父级和子级的复选框没有关联,使用过程中很不便,如图所示 自己给treelist添加父子级联动 /// <summary> /// 初始化TreeList,父 ...

  8. How do I reset Windows Update components?

    https://support.microsoft.com/en-us/kb/971058 Download and run the Windows Update Troubleshooter for ...

  9. DataSet.Clear Method ()

    Clears the DataSet of any data by removing all rows in all tables. 需要注意的是这个方法不会清空DataSet中的DataTable, ...

  10. 【原创】OPA857 TEST模式使用

    opa857 test mode: 配置opa857工作与test模式,设置tsst_sd为高电平连接到+Vs,test_in脚需要输入DC偏置以正确配置test模式.所需要增加的直流偏置大小因供电电 ...