本次操作的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使用的更多相关文章

  1. HBase中我认为比较常用的两个类:Scan和Filter

    学习HBase一段时间后,我认为HBase中比较常用,同时也是必须掌握的两个API是Scan和Filter.如下是我的理解: 1.Scan  ---- 扫描类 作用:用来对一个指定Table进行按行扫 ...

  2. HBase filter shell操作

    创建表 create 'test1', 'lf', 'sf' lf: column family of LONG values (binary value) -- sf: column family ...

  3. hbase查询,scan详解

    一.shell 查询 hbase 查询相当简单,提供了get和scan两种方式,也不存在多表联合查询的问题.复杂查询需通过hive创建相应外部表,用sql语句自动生成mapreduce进行.但是这种简 ...

  4. 【甘道夫】HBase(0.96以上版本号)过滤器Filter具体解释及实例代码

    说明: 本文參考官方Ref Guide,Developer API和众多博客.并结合实測代码编写.具体总结HBase的Filter功能,并附上每类Filter的对应代码实现. 本文尽量遵从Ref Gu ...

  5. HBase笔记--filter的使用

    HBASE过滤器介绍: 所有的过滤器都在服务端生效,叫做谓语下推(predicate push down),这样可以保证被过滤掉的数据不会被传送到客户端. 注意:        基于字符串的比较器,如 ...

  6. HBase(0.96以上版本)过滤器Filter详解及实例代码

    说明: 本文参考官方Ref Guide,Developer API和众多博客,并结合实测代码编写,详细总结HBase的Filter功能,并附上每类Filter的相应代码实现. 本文尽量遵从Ref Gu ...

  7. HBase Filter及对应Shell--转

    http://www.cnblogs.com/skyl/p/4807793.html 比较运算符 CompareFilter.CompareOp比较运算符用于定义比较关系,可以有以下几类值供选择: E ...

  8. Hbase Scan的方法

    public static void main(String[] args) throws IOException { //Scan类常用方法说明 //指定需要的family或column ,如果没有 ...

  9. HBase shell scan 过滤器用法总结

    比较器: 前面例子中的regexstring:2014-11-08.*.binary:\x00\x00\x00\x05,这都是比较器.HBase的filter有四种比较器: (1)二进制比较器:如’b ...

随机推荐

  1. gRPC java 客户端,服务器端通讯使用json格式

    使用 protobuf 作为通讯内容序列化的简单例子请看:http://www.cnblogs.com/ghj1976/p/5458176.html . 本文是使用 json 做为内容序列化的简单例子 ...

  2. Codeforces 665D Simple Subset [简单数学]

    题意: 给你n个数,让你从中选一个子集要求子集中的任何两个数相加都是质数. 思路: 一开始把自己坑了,各种想,后来发现一个简单的性质,那就是两个数相加的必要条件是这两个数之中必定一个奇数一个偶数,(除 ...

  3. poj 3026 Borg Maze 最小生成树 + 广搜

    点击打开链接 Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7097   Accepted: 2389 ...

  4. 2015 Multi-University Training Contest 6 Cake

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m soda and today i ...

  5. 【原】linux系统运维工具必备

    操作系统:CentOS※,Ubuntu 网站服务:apache,nginx※,tomcat,tengine 开发语言:php,python※,shell※ 数据库 :Mysql※ 代理相关:lvs,k ...

  6. (转)读取XML数据到treeView中

    原文地址,只为收藏:http://www.cnblogs.com/ylwn817/archive/2011/12/15/2288512.html /// <summary>        ...

  7. mysql 使用说明-3

    3.4 Getting Information About Databases and Tables 获取数据库和表格的信息 如果你忘记了数据库或者表格的名字怎么办?或者给定的表格的结构怎么办?(例如 ...

  8. MySQL数据库优化技术之SQL语句慢查询定位

    通过show status命令了解各种SQL的执行频率 MySQL客户端连接成功后,通过使用show [session|global] status 命令可以提供服务器状态信息: 其中的session ...

  9. MATLAB 实用函数

    MATLAB个人工具箱(MATLAB) mymail.m 可以利用MATLAB发送邮件(支持附件和群发),非常实用的函数,适用于:耗时很长的脚本完成后通知作者:外加定时器后用于信息推送:家庭监视器紧急 ...

  10. MSP430推荐网站

    http://www.amobbs.com/thread-5092914-1-1.html http://www.amobbs.com/thread-4701106-1-1.html