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();
        }
    }
  • 相关阅读:
    ES6---async, await, promise 综合例子
    ES6---Promise应用: async, await
    ES6---Promise 4: 更多案例
    掌握这两个技术点,你可以玩转AppCan前端开发
    AppCan4.0:开发者要做有价值的APP
    以“掌上东航”为例,论混合开发在企业级项目中的实践
    基于AppCan MAS系统,如何轻松实现移动应用数据服务?
    正益移动王国春:布局在是与不是之间
    【TOP10 APP】这些应用成了AppCan千人大会的焦点
    我爱我家:我为什么选择AppCan?
  • 原文地址:https://www.cnblogs.com/dongdone/p/5688820.html
Copyright © 2011-2022 走看看