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 row,String family,String qual,int value) throws IOException{
             HTable table = new HTable(conf, tableName);  
             Scan scan = new Scan();
             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.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()));  
                      }  
                  }  
         }

当设置为CompareOp.EQUAL时匹配不出来,

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

当设置为CompareOp.NOT_EQUAL时便有数据了:

=========== scanBySingleColumnValueFilter =======
zkb course:art 1356629381243 87


您的回应...

相关话题

查看全部

也许你感兴趣

换一批

热门标签

更多