我有一个列族,名为domes\u api,其中包含rowkey的行数:/bt=??/bm=??/mk=??/se=??:
/bt=1/bm=MN/mk=344/se=23394/odds_api
/bt=1/bm=BY/mk=344/se=23394/odds_api
/bt=1/bm=SN/mk=344/se=23394/odds_api
/bt=1/bm=BB/mk=344/se=23394/odds_api
/bt=1/bm=SF/mk=344/se=23394/odds_api
/bt=1/bm=XY/mk=344/se=23394/odds_api
我想根据bm值列表进行过滤,也称为基于bm=sf,bb,mn的过滤。
为此,我创建了一个filterlist of must \u pass \u one with 1 to many rowfilters(取决于用户请求的值数量)
public ResultScanner scan(String id , List<String> bms) throws BigTableGetException {
try{
Table table = connection.getTable(TableName.valueOf(this.tableName));
Scan scan = new Scan();
scan.addFamily(Bytes.toBytes("odds_api"));
FilterList mainFilterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
bms.stream()
.forEach(bm -> {
mainFilterList.addFilter(new RowFilter(CompareOp.EQUAL, new RegexStringComparator("/bt="+id+"/bm="+bm+".*")));
});
System.out.println("this is the filter list " + mainFilterList.toString());
scan.setFilter(mainFilterList);
return table.getScanner(scan);
}catch (IOException ex){
throw new BigTableGetException("Failed to get rows in BigTable", ex);
}
}
(我知道——对一个foreach来说毫无意义的流!)
如果只指定了一个bm,则可以正常工作,打印语句:
this is the filter list FilterList OR (1/1): [RowFilter (EQUAL, /bt=1/bm=B4.*)]
但是,如果指定了多个,则返回所有内容,打印语句:
this is the filter list FilterList OR (2/2): [RowFilter (EQUAL, /bt=1/bm=B4.*), RowFilter (EQUAL, /bt=1/bm=PP.*)]
事实上,如果我输入两个或多个“不正确”的bm值,它仍然返回所有内容!
我读过:https://www.oreilly.com/library/view/hbase-the-definitive/9781449314682/ch04.html
我也试过移动bt=?筛选出一个单独的必须通过所有筛选,然后有另一个列筛选bm=?
this is the filter list FilterList AND (2/2): [FilterList AND (1/1): [RowFilter (EQUAL, .*bt=1)], FilterList OR (2/2): [RowFilter (EQUAL, .*/bm=B4.*), RowFilter (EQUAL, .*/bm=PP.*)]]
同样的问题。
我一定是错过了什么明显的,任何帮助将不胜感激。
hbase版本:
<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-hbase-1.x</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-hbase-1.x-hadoop</artifactId>
<version>1.4.0</version>
</dependency>
1条答案
按热度按时间6za6bjd01#
你考虑过用一个正则表达式吗?”/bt=foo/bm=(a | b | c | d)。*“应该可以。
另外,请提出一个问题https://github.com/googlecloudplatform/cloud-bigtable-client. 在客户端代码中似乎确实有一个bug。