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 ...
随机推荐
- ural 1115,搜索
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1115 题意:n个军舰,m个海岸线,各个长度给出,求n个军舰怎么组成这些海岸线. 思路很简 ...
- Mybaits 之根据集合查询和逗号分隔的子查询
这是我们的mapper要根据传入一个集合进行查询: List<ExtKeywordCategory> findListByIds(List<ExtKeywordFkCategory& ...
- 使用 JavaScript
我们要用 JavaScript,但是把它写在哪里呢? 这里 ↘ 1. HTML 页面中 . 2. 单独的一个文件中,文件后缀名是“.js”. ——————————————————— ...
- php获取本周和上周的开始日期和结束日期
<?php header('Content-type: text/html; charset=utf-8'); $date=date('Y-m-d'); //当前日期 $first=1; //$ ...
- 插入排序和一点小感悟(c++版)
很早之前,为了应付数据结构考试.花了一星期多看了数据结构,当时觉得也没什么难的. 过了老久,总算是招报应了,做笔试题发现其实所有理解只是在表面,实际上我并不会实现,确实是这样,学术这东西真没捷径,还是 ...
- 如何重置CentOS/RHEL 7中遗忘的根用户帐户密码
你有没有遇到过这种情况:想不起来Linux系统上的用户帐户密码?要是你忘了根用户密码,情况就更为糟糕.你无法执行任何面向整个系统的变更.要是你忘了用户密码,很容易使用根帐户来重置密码. 可要是你忘了根 ...
- Cheatsheet: 2014 01.01 ~ 01.14
.NET 15 reasons why I can't work without JetBrains ReSharper Web Web scraping with Node.js Koa.js : ...
- Nodejs之socket广播
nodejs发送udp广播还是蛮简单的,我们先写个服务器用于接收广播数据,代码如下: var dgram = require("dgram"); var server = dgra ...
- weblogic解密工具
import org.bouncycastle.jce.provider.BouncyCastleProvider; import sun.misc.BASE64Decoder; import jav ...
- poj 2398 (叉积+二分)
http://poj.org/problem?id=2398 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...