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();
        }
    }
  • 相关阅读:
    ZOJ-3230-Solving the Problems
    zoj-3410-Layton's Escape
    cin输入超过文本末尾
    sizeof('a')
    WPF TranslatePoint/TransformToVisual 总返回零
    Lock-free multi-threading
    c++0X 用字符串调用函数
    Vim 的c++语法补齐
    Reentrancy VS Thread safe
    内存屏障
  • 原文地址:https://www.cnblogs.com/dongdone/p/5688820.html
Copyright © 2011-2022 走看看