我有一个名为odds_api的列族,具有行键的行数:/ 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进行过滤。
为此,我创建了一个MUST_PASS_ONE的filterList,其中有1到许多rowFilter(取决于用户请求的值)
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的print语句时,此方法工作正常:
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 =?过滤出一个单独的MUST_PASS_ALL过滤器,然后为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>
答案 0 :(得分:2)
您是否考虑过使用单个正则表达式? “ /bt=FOO/bm=(A|B|C|D).*”应该起作用。
另外,请在https://github.com/GoogleCloudPlatform/cloud-bigtable-client中提出一个问题。客户端代码中似乎确实存在错误。