1  列值过滤器

  SingleColumnValueFilter 对列值进行过滤。

    @Test
public void scanDataByFilter() throws IOException {
Table table = connection.getTable(TableName.valueOf("user"));
Scan scan = new Scan();
SingleColumnValueFilter singleColumnValueFilter = new SingleColumnValueFilter(Bytes.toBytes("info1"),
Bytes.toBytes("name"), CompareOp.GREATER, Bytes.toBytes("lisi"));
scan.setFilter(singleColumnValueFilter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
byte[] name = result.getValue(Bytes.toBytes("info1"), Bytes.toBytes("name"));
byte[] sex = result.getValue(Bytes.toBytes("info1"), Bytes.toBytes("sex"));
byte[] age = result.getValue(Bytes.toBytes("info1"), Bytes.toBytes("age"));
byte[] address = result.getValue(Bytes.toBytes("info1"), Bytes.toBytes("address"));
System.out.println("name=" + Bytes.toString(name) + ",sex=" + Bytes.toInt(sex) + ",age=" + Bytes.toInt(age)
+ ",address=" + Bytes.toString(address)); }
}

  扫描全表,用过滤器进行匹配,找出出满足过滤条件的元素。

  SingleColumnValueFilter

  参数:列族、列名、操作符、列值

  操作符可以为:

  CompareOp.LESS:小于

  CompareOp.LESS_OR_EQUAL:小于或者等于

  CompareOp.EQUAL:等于

  CompareOp.NOT_EQUAL:不等于

  CompareOp.GREATER_OR_EQUAL:大于或者等于

  CompareOp.GREATER:大于

  CompareOp.NO_OP:不比较

2 列名前缀过滤器

  ColumnPrefixFilter 对列名进行过滤

@Test
public void scanDataByFilter2() throws IOException {
Table table = connection.getTable(TableName.valueOf("user"));
Scan scan = new Scan();
ColumnPrefixFilter columnPrefixFilter = new ColumnPrefixFilter(Bytes.toBytes("name_"));
scan.setFilter(columnPrefixFilter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) { Cell[] rawCells = result.rawCells();
for (Cell cell : rawCells) {
System.out.println("value = " + Bytes.toString(CellUtil.cloneValue(cell)));
System.out.println("family = " + Bytes.toString(CellUtil.cloneFamily(cell)));
System.out.println("qualifier = " + Bytes.toString(CellUtil.cloneQualifier(cell)));
}
}
}

  找出user表中,以'name_'开头的列

3 多个列值前缀过滤器

    @Test
public void testMultipleColumnPrefixFilter() throws IOException {
Table table = connection.getTable(TableName.valueOf("user"));
Scan scan = new Scan();
byte[][] prefixes = new byte[][] { Bytes.toBytes("name"), Bytes.toBytes("age") };
MultipleColumnPrefixFilter multipleColumnPrefixFilter = new MultipleColumnPrefixFilter(prefixes);
scan.setFilter(multipleColumnPrefixFilter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) { Cell[] rawCells = result.rawCells();
for (Cell cell : rawCells) {
System.out.println("value = " + Bytes.toString(CellUtil.cloneValue(cell)));
System.out.println("family = " + Bytes.toString(CellUtil.cloneFamily(cell)));
System.out.println("qualifier = " + Bytes.toString(CellUtil.cloneQualifier(cell)));
}
}
}

  用于匹配多列,找出以‘name’和‘age’开头的列

4 rowKey过滤器  

@Test
public void testRowFilter() throws IOException {
Table table = connection.getTable(TableName.valueOf("user"));
Scan scan = new Scan();
RowFilter rowFilter = new RowFilter(CompareOp.EQUAL, new RegexStringComparator("^00004"));
scan.setFilter(rowFilter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) { Cell[] rawCells = result.rawCells();
for (Cell cell : rawCells) {
System.out.println("value = " + Bytes.toString(CellUtil.cloneValue(cell)));
System.out.println("family = " + Bytes.toString(CellUtil.cloneFamily(cell)));
System.out.println("qualifier = " + Bytes.toString(CellUtil.cloneQualifier(cell)));
}
}
}

  RegexStringComparator("^00004")正则计较器,支持正则表达式。过滤rowkey是以‘’00004‘开头的行。

HBase第三章 过滤器的更多相关文章

  1. HBase in Action前三章笔记

    近期接触HBase,看了HBase In Action的英文版.開始认为还行,做了些笔记.可是兴许看下去,越来越感觉到实战这本书比較偏使用上的细节,对于HBase的具体设计涉及得很少.把前三章的一些笔 ...

  2. Hbase学习(三)过滤器 java API

    Hbase学习(三)过滤器 HBase 的基本 API,包括增.删.改.查等. 增.删都是相对简单的操作,与传统的 RDBMS 相比,这里的查询操作略显苍白,只能根据特性的行键进行查询(Get)或者根 ...

  3. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  4. 精通Web Analytics 2.0 (5) 第三章:点击流分析的奇妙世界:指标

    精通Web Analytics 2.0 : 用户中心科学与在线统计艺术 第三章:点击流分析的奇妙世界:指标 新的Web Analytics 2.0心态:搞定它.新的闪亮系列工具:是的.准备好了吗?当然 ...

  5. Mysql技术内幕-笔记-第三章 查询处理

    第三章 查询处理 逻辑查询处理:(8) SELECT (9) DISTINCT <select_list> (1) FROM <left_table> (3) <join ...

  6. 第三章Hibernate关联映射

    第三章Hibernate关联映射 一.关联关系 类与类之间最普通的关系就是关联关系,而且关联是有方向的. 以部门和员工为列,一个部门下有多个员工,而一个员工只能属于一个部门,从员工到部门就是多对一关联 ...

  7. CentOS 7.4 初次手记:第三章 CentOS基础了解

    第三章 CentOS基础了解... 36 第一节 语言编码.终端... 36 I 查看语言编码... 36 II Tty?.pts/?. 36 第二节 bash/sh command. 38 I 查找 ...

  8. [转]TEC1401.Report开发技术总结 - 第三章 使用Oracle Reports开发报表-创建一个分组报表(2/4)

    本文转自:http://blog.csdn.net/deepsea_allen/article/details/53900284 第三章   创建一个分组报表 1.     建立数据模型 数据模型用于 ...

  9. CentOS6安装各种大数据软件 第三章:Linux基础软件的安装

    相关文章链接 CentOS6安装各种大数据软件 第一章:各个软件版本介绍 CentOS6安装各种大数据软件 第二章:Linux各个软件启动命令 CentOS6安装各种大数据软件 第三章:Linux基础 ...

随机推荐

  1. Java并发案例02---生产者消费者问题

    package example; import java.util.LinkedList; import java.util.concurrent.TimeUnit; public class MyC ...

  2. [转]MBTiles 离线地图演示 - 基于 Google Maps JavaScript API v3 + SQLite

    MBTiles 是一种地图瓦片存储的数据规范,它使用SQLite数据库,可大大提高海量地图瓦片的读取速度,比通过瓦片文件方式的读取要快很多,适用于Android.IPhone等智能手机的离线地图存储. ...

  3. 启动 NFS 守护进程:rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)

    启动 NFS 守护进程:rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused) rpc.nfsd: unable t ...

  4. 字符型设备驱动程序-first-printf以及点亮LED灯(三)

    根据  字符型设备驱动程序-first-printf以及点亮LED灯(二) 学习 修改函数 中的printf 为 printk. #include <linux/module.h> /* ...

  5. linux SVN添加新用户

    首先找到用户文件:authz.conf; 用vi 编辑authz.conf文件在develps 后面添加你要添加的用户名:如图:  上图:cheny就是我后面添加上去的用户名 按Esc :wq保存au ...

  6. GPUImage源码解读之GLProgram

    简述 GLProgram是GPUImage中代表openGL ES 中的program,具有glprogram功能.其实是作者对OpenGL ES program的面向对象封装 初始化 - (id)i ...

  7. Java实现目的选层电梯的调度

    一.前言 本次博客我将简单介绍一下前两次的电梯作业,并简单解析一下我的程序结构,进一步对我的第二次作业的算法核心和一些想法做一些分享,我的电梯设计算法并不是由调度器来决定电梯的捎带与否,而是由电梯自主 ...

  8. 利用纯JS和HTML Canvas生成随机迷宫过程中产生的有趣的事情

    上效果图: #先看生成随机迷宫的代码吧↓ <html> <head> <title>生成随机迷宫v1.0</title> </head> & ...

  9. VmWare入门指南

    记得以前有大佬曾教过我们用win10的自带双系统运行Ubuntu,但这玩意儿好像玩起来并不简单(反正本人试了一上午也没成功),而且这个系统是和windows交互的,我们也很难调整性能参数.今天,我来教 ...

  10. input的默认样式去除

    outline:none;-----可去除input=text,的输入框输入时的亮边.