zoukankan      html  css  js  c++  java
  • hbase 跳转过滤器skipfilter

    用于跳过整个行键,需要和其他过滤器一起使用,本例SkipFilter和ValueFilter过滤器组合使用过滤不符合条件的行,

    如果不配合SkipFiter,ValueFilter只过滤单元值包含的列。

        private static void skipFilterData() throws IOException{
            Table table = helper.getConnection().getTable(TableName.valueOf("demoTable"));
            Filter filter = new ValueFilter(CompareOperator.NOT_EQUAL,new BinaryComparator(Bytes.toBytes("val2")));
    
            Scan scan = new Scan();
            scan.setFilter(filter);
    
            ResultScanner scanner1 = table.getScanner(scan);
            System.out.println("Results of scan #1:");
            int n = 0;
            for (Result result : scanner1) {
                for (Cell cell : result.rawCells()) {
                    System.out.println("Cell: " + cell + ", Value: " +
                            Bytes.toString(cell.getValueArray(), cell.getValueOffset(),
                                    cell.getValueLength()));
                    n++;
                }
            }
            scanner1.close();
    
            //应用跳转过滤
            Filter skipFilter  = new SkipFilter(filter);
            Scan scan2 = new Scan();
            scan2.setFilter(skipFilter);
            ResultScanner scanner2 = table.getScanner(scan2);
            System.out.println("Total cell count for scan #1: " + n);
            n = 0;
            System.out.println("Results of scan #2:");
            for (Result result : scanner2) {
                for (Cell cell : result.rawCells()) {
                    System.out.println("Cell: " + cell + ", Value: " +
                            Bytes.toString(cell.getValueArray(), cell.getValueOffset(),
                                    cell.getValueLength()));
                    n++;
                }
            }
            scanner2.close();
            System.out.println("Total cell count for scan #2: " + n);
    
        }

    表中数据:

    hbase(main):005:0> scan 'demoTable'
    ROW                          COLUMN+CELL                                                                      
     row1                        column=cf1:qual1, timestamp=5, value=row1_batch1                                 
     row1                        column=cf1:qual2, timestamp=2, value=val2                                        
     row1                        column=cf1:qual3, timestamp=3, value=val3                                        
     row1                        column=cf2:qual1, timestamp=1, value=val1                                        
     row1                        column=cf2:qual2, timestamp=5, value=row1_batch2                                 
     row1                        column=cf2:qual3, timestamp=3, value=val3                                        
     row2                        column=cf1:qual1, timestamp=1, value=val1                                        
     row2                        column=cf1:qual3, timestamp=3, value=val3                                        
     row2                        column=cf2:qual1, timestamp=1, value=val1                                        
     row2                        column=cf2:qual2, timestamp=2, value=val2                                        
     row2                        column=cf2:qual3, timestamp=3, value=val3                                        
     row3                        column=cf1:qual1, timestamp=1, value=value1  

    输出结果:ValueFilter过滤只过滤某个Cell,配合SkipFilter过滤了整行数据

    Cell: row1/cf1:qual1/5/Put/vlen=11/seqid=0, Value: row1_batch1
    Cell: row1/cf1:qual3/3/Put/vlen=4/seqid=0, Value: val3
    Cell: row1/cf2:qual1/1/Put/vlen=4/seqid=0, Value: val1
    Cell: row1/cf2:qual2/5/Put/vlen=11/seqid=0, Value: row1_batch2
    Cell: row1/cf2:qual3/3/Put/vlen=4/seqid=0, Value: val3
    Cell: row2/cf1:qual1/1/Put/vlen=4/seqid=0, Value: val1
    Cell: row2/cf1:qual3/3/Put/vlen=4/seqid=0, Value: val3
    Cell: row2/cf2:qual1/1/Put/vlen=4/seqid=0, Value: val1
    Cell: row2/cf2:qual3/3/Put/vlen=4/seqid=0, Value: val3
    Cell: row3/cf1:qual1/1/Put/vlen=6/seqid=0, Value: value1
    Total cell count for scan #1: 10
    Results of scan #2:
    Cell: row3/cf1:qual1/1/Put/vlen=6/seqid=0, Value: value1
    Total cell count for scan #2: 1
  • 相关阅读:
    for 循环、序列和range()
    Python 中的 / 运算符的一切运算结果都是浮点数
    web如何测试
    性能测试中会遇到的瓶颈
    APP测试之内存命令查询
    接口测试常见的题目
    接口测试基础知识
    异或和之和 异或问题
    DP?
    Matrix Power Series
  • 原文地址:https://www.cnblogs.com/asker009/p/10701932.html
Copyright © 2011-2022 走看看