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 ...
随机推荐
- 字典查找、linq、foreach、yield等几种查找性能对比
先上代码,以1千万记录的内存查找测试: List<Student> stuList = new List<Student>(); Dictionary<int, Stud ...
- (medium)LeetCode 233.Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...
- bash 学习笔记
shell:能够操作应用程序的接口就称为shell. Linux由C编写的. TAB键的使用 alias:设置别名
- hbase的rowkey简单设计
问题: 需要查询某一用户某时间做了什么,PlatID和vopenid可以保证一个用户唯一,但同一时间同一用户可能日志有多条. 使用PlatID(int).vopenid(int)和dtTime(dat ...
- PL/SQL常用设置 可看引用位置更清晰直观 引自:http://blog.csdn.net/xiaoqforever/article/details/27695569
引自:http://blog.csdn.net/xiaoqforever/article/details/27695569 1,登录后默认自动选中My Objects 默认情况下,PLSQL Deve ...
- The init method
The init method is a special method that gets invoked when an object is instantiated. Its full name ...
- yii中第三方库
yii中存在一些路径别名:ext:表示包含了所有第三方扩展的目录 参考:http://www.yiiframework.com/doc/guide/1.1/zh_cn/basics.namespac ...
- PAT1015. Reversible Primes
//题的理解是n在基数b中的的表示中,正序和逆序值都是素数,但是其实可直接判断n,因为n在b中的正常序列值就是再换成十进制就是n,但是不A:不知道为什么 用笨方法,先把n展开成b进制,正常计算其实是翻 ...
- 用C#访问Dynamic AX的WebService.
第 1 步:创建 C# WinForm 应用程序 针对本演练,您将创建访问报表服务器 Web 服务的简单控制台应用程序.本演练假定您是在 Visual Studio 环境中进行开发的.测试范例基于VS ...
- solr5.5教程-solrconfig.xml,加载schema.xml
布署完成后,接下来要更深入的研究solr的原理和使用. 首先进入testcore这个文件夹下面,发现这个core的conf里并没有schema.xml.那么数据格式是在哪里定义的呢? 打开 solr_ ...