本次操作的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. Oracle中对表的操作

    表的创建与管理 创建表: CREATE TABLE TABLE_NAME ( COLUMN_NAME TYPE [DEFAULT VALUE], COLUMN_NAME TYPE [DEFAULT V ...

  2. go get 获得 golang.org 的项目

    go get 用来动态获取远程代码包的,目前支持的有BitBucket.GitHub.Google Code和Launchpad.这个命令在内部实际上分成了两步操作:第一步是下载源码包,第二步是执行g ...

  3. flask log

    import logging from logging.handlers import RotatingFileHandler from flask import Flask app = Flask( ...

  4. mm

    1. 实施例子  http://wenku.baidu.com/view/d01d951dfad6195f312ba6e8.html 2. internal number range即内部给号,指系统 ...

  5. Net文章汇总帖

    DevExpress:Data Grid ExamplesHow to: Initialize Cells in Newly Created RowsHow to: Set a Cell Value ...

  6. (easy)LeetCode 237.Delete Node in a Linked List

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  7. XML文件操作类--创建XML文件

    这个类是在微软XML操作类库上进行的封装,只是为了更加简单使用,包括XML类创建节点的示例. using System; using System.Collections; using System. ...

  8. ASP.NET MVC开发微信(三)

  9. 制作东皇3.2的安装U盘-黑苹果之路

    每次使用硬盘映像安装需要先装windows,制作东皇3.2安装分区,再装bootthink,再通过bootthink加载东皇3.2的分区进行安装,非常繁琐.尝试制作U盘来直接安装东皇3.2.过程如下: ...

  10. vc 判断哪个按键 被按下 消息 按键 状态

    测试Numlock 是否是亮的 环境控制台程序: #include "stdafx.h" #include <stdio.h> #include <conio.h ...