2017-02-22 81 views

回答

1

如果你沒有AAAA固定的,你可以這樣做:

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE); 
String[] matches=new String[]{"AAAA","BBBB"}; 
    for (String match:matches) { 
     byte[] rk = Bytes.toBytesBinary("??" + match + "??????????????"); 
     byte[] fuzzyVal = new byte[]{1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 
     List<Pair<byte[], byte[]>> pairs = new ArrayList<>(); 
     pairs.add(new Pair<>(rk, fuzzyVal)); 
     filterList.addFilter(new FuzzyRowFilter(pairs)); 
    } 
Scan scan=new Scan(); 
    scan.setFilter(filterList); 

這將過濾器的基礎上,基於FilterList.Operator.MUST_PASS_ONE列表和滿足所有fuzzyFilters。 根據您的要求,請繼續並相應地進行修改。

0

很抱歉,但使用,

FilterList filterList = new FilterList(/*FilterList.Operator.MUST_PASS_ONE*/); 
    String[] matches=new String[]{"1609","1610"}; 
     for (String match:matches) { 
      byte[] rk = Bytes.toBytesBinary("??" + match + "??????????????"); 
      byte[] fuzzyVal = new byte[]{1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 
      List<Pair<byte[], byte[]>> pairs = new ArrayList<>(); 
      pairs.add(new Pair<>(rk, fuzzyVal)); 
      filterList.addFilter(new FuzzyRowFilter(pairs)); 
     } 
    Scan scan_fuzzy=new Scan(); 
    scan_fuzzy.setFilter(filterList); 

    ResultScanner rs_fuzzy = table.getScanner(scan); 

    for(Result result : rs_fuzzy) { 
     System.out.println(result); 
     System.out.println("Value: " + Bytes.toString(result.getValue(FAMILY,COLUMN))); 
    } 

我的結果不包含對應rowkey只是該行:02160901222720647002

,但所有的行我表(和rowkey)