zoukankan      html  css  js  c++  java
  • scan的filter使用

    本次操作的hbase的t1表的数据是:

    hbase(main):015:0> scan 't1'
    ROW                                              COLUMN+CELL                                                                                                                                 
     1                                               column=f1:age, timestamp=1468824267106, value=10                                                                                            
     1                                               column=f1:gender, timestamp=1468824289990, value=male                                                                                       
     1                                               column=f1:name, timestamp=1468824137463, value=zhangsan                                                                                     
     2                                               column=f1:name, timestamp=1468824236014, value=lisi                                                                                         
     3                                               column=f1:name, timestamp=1468824247109, value=wangwu                                                                                       
     4                                               column=f1:birthday, timestamp=1468825870158, value=1993                                                                                     
     4                                               column=f1:name, timestamp=1468825659207, value=zhaoliu                                                                                      
     a1                                              column=f1:name, timestamp=1469000782113, value=a1                                                                                           
     a2                                              column=f1:name, timestamp=1469000805242, value=a2                                                                                           
     a3                                              column=f1:name, timestamp=1469000813427, value=a3                                                                                           
    7 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))+"	"+new String(CellUtil.cloneQualifier(cell))+"	"+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))+"	"+new String(CellUtil.cloneQualifier(cell))+"	"+new String(CellUtil.cloneValue(cell)));
                }
            }
            hTable.close();
        }
    }
  • 相关阅读:
    POJ 3259 Wormholes【BellmanFord】
    POJ 2960 SNim【SG函数的应用】
    ZOJ 3578 Matrixdp水题
    HDU 2897 邂逅明下【bash博弈】
    BellmanFord 算法及其优化【转】
    【转】几个Java的网络爬虫
    thinkphp 反字符 去标签 自动加点 去换行 截取字符串 冰糖
    php 二维数组转 json文本 (jquery datagrid 数据格式) 冰糖
    PHP 汉字转拼音(首拼音,所有拼音) 冰糖
    设为首页与加入收藏 兼容firefox 冰糖
  • 原文地址:https://www.cnblogs.com/dongdone/p/5688820.html
Copyright © 2011-2022 走看看