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();
        }
    }
  • 相关阅读:
    hdu 3714
    sql 函数 DATEADD 使用
    mvc的IIS 配置问题 runAllManagedModulesForAllRequests 与 HtmlFileHandler
    移动端日历控件 mobiscroll 的简单使用、参数设置
    sql中判断是否存在某个对象
    SQLServer中的变量:局部变量,全局变量
    键盘对照表
    [PyQt]在Windows系统中安装Eric6
    [Python]使用QRCode生成彩色二维码
    [PyQt]PyQt5连接SQL Server数据库,并读取所有数据库名称
  • 原文地址:https://www.cnblogs.com/dongdone/p/5688820.html
Copyright © 2011-2022 走看看