scan的filter使用
本次操作的hbase的t1表的数据是:
hbase(main)::> scan 't1'
ROW COLUMN+CELL
column=f1:age, timestamp=, value=
column=f1:gender, timestamp=, value=male
column=f1:name, timestamp=, value=zhangsan
column=f1:name, timestamp=, value=lisi
column=f1:name, timestamp=, value=wangwu
column=f1:birthday, timestamp=, value=
column=f1:name, timestamp=, value=zhaoliu
a1 column=f1:name, timestamp=, value=a1
a2 column=f1:name, timestamp=, value=a2
a3 column=f1:name, timestamp=, value=a3
row(s) in 0.0530 seconds
需求1:查询rk为数字的全部记录
public class TestFilter {
public static void main(String[] args) throws Exception {
new TestFilter().test1();
} public void test1() throws Exception{
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "hadoop26:2181");
conf.set("hbase.rootdir", "hdfs://hadoop26:9000/hbase");
HTable hTable = new HTable(conf, "t1");
Scan scan = new Scan();
scan.setStartRow("/".getBytes());//重点是在这里,因为rk是按照字节顺序排序的,/的asc在数字之前
scan.setStopRow(":".getBytes());
ResultScanner scanner = hTable.getScanner(scan);
for (Result result : scanner) {
System.out.println(new String(result.getRow()));
Cell[] rawCells = result.rawCells();
for (Cell cell : rawCells) {
System.out.println(new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell)));
}
}
hTable.close();
}
}
需求2:查询以字母a开头的数据
public class TestFilter {
public static void main(String[] args) throws Exception {
new TestFilter().test2();
} public void test2() throws Exception{
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "hadoop26:2181");
conf.set("hbase.rootdir", "hdfs://hadoop26:9000/hbase");
HTable hTable = new HTable(conf, "t1");
Scan scan = new Scan();
Filter filter = new RowFilter(CompareOp.EQUAL,new RegexStringComparator("^a"));
scan.setFilter(filter);
ResultScanner scanner = hTable.getScanner(scan);
for (Result result : scanner) {
System.out.println(new String(result.getRow()));
Cell[] rawCells = result.rawCells();
for (Cell cell : rawCells) {
System.out.println(new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell)));
}
}
hTable.close();
}
}
scan的filter使用的更多相关文章
- HBase中我认为比较常用的两个类:Scan和Filter
学习HBase一段时间后,我认为HBase中比较常用,同时也是必须掌握的两个API是Scan和Filter.如下是我的理解: 1.Scan ---- 扫描类 作用:用来对一个指定Table进行按行扫 ...
- HBase filter shell操作
创建表 create 'test1', 'lf', 'sf' lf: column family of LONG values (binary value) -- sf: column family ...
- hbase查询,scan详解
一.shell 查询 hbase 查询相当简单,提供了get和scan两种方式,也不存在多表联合查询的问题.复杂查询需通过hive创建相应外部表,用sql语句自动生成mapreduce进行.但是这种简 ...
- 【甘道夫】HBase(0.96以上版本号)过滤器Filter具体解释及实例代码
说明: 本文參考官方Ref Guide,Developer API和众多博客.并结合实測代码编写.具体总结HBase的Filter功能,并附上每类Filter的对应代码实现. 本文尽量遵从Ref Gu ...
- HBase笔记--filter的使用
HBASE过滤器介绍: 所有的过滤器都在服务端生效,叫做谓语下推(predicate push down),这样可以保证被过滤掉的数据不会被传送到客户端. 注意: 基于字符串的比较器,如 ...
- HBase(0.96以上版本)过滤器Filter详解及实例代码
说明: 本文参考官方Ref Guide,Developer API和众多博客,并结合实测代码编写,详细总结HBase的Filter功能,并附上每类Filter的相应代码实现. 本文尽量遵从Ref Gu ...
- HBase Filter及对应Shell--转
http://www.cnblogs.com/skyl/p/4807793.html 比较运算符 CompareFilter.CompareOp比较运算符用于定义比较关系,可以有以下几类值供选择: E ...
- Hbase Scan的方法
public static void main(String[] args) throws IOException { //Scan类常用方法说明 //指定需要的family或column ,如果没有 ...
- HBase shell scan 过滤器用法总结
比较器: 前面例子中的regexstring:2014-11-08.*.binary:\x00\x00\x00\x05,这都是比较器.HBase的filter有四种比较器: (1)二进制比较器:如’b ...
随机推荐
- struts(五) 使用通配符 接收参数
1.使用通配符简化配置 约定优于配置 <action name="student*" class="com.gc.StudentAction" metho ...
- HDU 4081 Qin Shi Huang's National Road System [次小生成树]
题意: 秦始皇要建路,一共有n个城市,建n-1条路连接. 给了n个城市的坐标和每个城市的人数. 然后建n-2条正常路和n-1条魔法路,最后求A/B的最大值. A代表所建的魔法路的连接的城市的市民的人数 ...
- 【转】java内部类的作用
http://andy136566.iteye.com/blog/1061951/ 推荐一. 定义 放在一个类的内部的类我们就叫内部类. 二. 作用 1.内部类可以很好的实现隐藏 一般的非内部类,是不 ...
- Oracle GoldenGate 11.2 OGG-01168(转)
为客户部署的Oracle GoldenGate在测试阶段出现如下的错误: 2012-04-24 10:45:20 ERROR OGG-01168 Oracle GoldenGate Deliv ...
- 03-position和anchorPoint
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- 移植ok6410
tftp u-boot.bin http://blog.csdn.net/link_hui/article/details/5593518 LED driver http://blog.csdn.ne ...
- 慧自文档:代替 Everything 来快速查找文件的,实现文件显示在文件夹的层次结构中
1. 搜索功能和Everything一样快和强大 具有 Everything 搜索快.搜索功能强等优点, 解决了不能方便选择搜索哪个文件夹, 解决了不能同一个画面进行预览等问题 2.文件直接显示到文件 ...
- Effective Modern C++翻译(4)-条款3:了解decltype
条款3 了解decltype decltype是一个有趣的东西,给它一个变量名或是一个表达式,decltype会告诉你这个变量名或是这个表达式的类型,通常,告诉你的结果和你预测的是一样的,但是偶尔的结 ...
- Facebook三种分享方式
一.去Facebook开发者中心注册APP,获取APP ID https://developers.facebook.com 二.导入 FBSDKCoreKit.Framework, FBSDKLog ...
- Could not find action or result
[WARN ] 2013-11-21 14:08:16 :Could not find action or resultThere is no Action mapped for namespace ...