hbase的过滤 Filter 之SingleColumnValueFilter

scan的操作:

hbase(main):002:0> scan 'scores'
ROW                              COLUMN+CELL                                                                                  
 zkb                             column=course:, timestamp=1356629086396, value=90                                            
 zkb                             column=course:art, timestamp=1356629086401, value=87                                         
 zkb                             column=course:math, timestamp=1356629086398, value=97                                        
 zkb                             column=grade:, timestamp=1356629086385, value=5                                              
1 row(s) in 0.2260 seconds

 


    public static void scanBySingleColumnValueFilter(String tableName,
            String family, String qual, String value) throws IOException {//这个地方需要注意value的数据类型,否则及其容易出错
        HTable table = new HTable(conf, tableName);
        byte[] b_family = Bytes.toBytes(family);
        byte[] b_qual = Bytes.toBytes(qual);
        byte[] b_value = Bytes.toBytes(value);

        FilterList filterList = new FilterList();
        SingleColumnValueFilter singleColumnValueFilter = new SingleColumnValueFilter(
                b_family, b_qual, CompareOp.EQUAL, b_value);

        // singleColumnValueFilter.setFilterIfMissing(true);
        filterList.addFilter(singleColumnValueFilter);

        Scan scan = new Scan();
        scan.setFilter(filterList);
        scan.addColumn(b_family, b_qual);
        ResultScanner rs = table.getScanner(scan);
        showResultScanner(rs);
    }

show结果

public static void showResultScanner(ResultScanner rs){
                for(Result r:rs){  
                      for(KeyValue kv : r.raw()){  
                         System.out.print(new String(kv.getRow()) + " ");  
                         System.out.print(new String(kv.getFamily()) + ":");  
                         System.out.print(new String(kv.getQualifier()) + " ");  
                         System.out.print(kv.getTimestamp() + " ");  
                         System.out.println(new String(kv.getValue()));  
                      }  
                  }  
         }

在主函数里调用的时候

System.out.println("=========== scanBySingleColumnValueFilter ======="); 

 HBaseClient.scanBySingleColumnValueFilter(tablename, "course", "art", "87");

结果:

=========== scanBySingleColumnValueFilter =======
zkb course:art 1357053302173 87。。。。没什么问题




评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值