我对HBase api很新,并且在执行以下操作时会看到一些奇怪的结果。
我们正在尝试基于多个过滤器进行扫描。我想通过所有过滤条件。我使用以下代码。
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
Filter pageFilter = new PageFilter(5000);
filterList.addFilter(pageFilter);
SingleColumnValueFilter filterOne = new SingleColumnValueFilter(Bytes.toBytes(COLUMN_FAMILY),
Bytes.toBytes(COLUMN_NAME1), CompareOp.EQUAL, Bytes.toBytes(value1));
filterList.addFilter(filterOne);
SingleColumnValueFilter filterTwo = new SingleColumnValueFilter(Bytes.toBytes(COLUMN_FAMILY),
Bytes.toBytes(COLUMN_NAME2), CompareOp.EQUAL, Bytes.toBytes(value2));
filterList.addFilter(filterOne);
filterList.addFilter(filterTwo);
//Scan
Scan scan = new Scan();
scan.setFilter(filterList);
Result result;
try {
scanner = hTable.getScanner(scan);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while ((result = scanner.next()) != null) {
//print the result.
}
//If I am adding multiple SingleColumnValueFilter and I am not doing a addCoulmn() to the scan I am not getting any result even though there are records.
//If I am adding a column to scan then I am seeing results. Initially the result set is matching my filter condition but if I am running for bigger hbase data set then I am seeing bad results.
//If I am adding multiple addCoulmn() to my scan then I am not seeing any result
我试图寻找合适的例子,但它们似乎都没有起作用。非常感谢在这方面的任何帮助。提前谢谢。
答案 0 :(得分:0)
您指定了所有过滤器必须通过的FilterList
(如“AND”行为)。在过滤器列表中,您有两个SingleColumnValueFilter
是矛盾的:他们说列COLUMN_FAMILY:COLUMN_NAME
必须同时等于value1和value2。我认为这就是为什么你没有得到第一和第三评论背景的结果。
关于您的第二条评论,我认为您必须记住,仅当“扫描”中存在该列时才会应用SingleColumnValueFilter
。这可能是你所看到的解释。查看setFilterIfMissing(boolean)
方法:https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/filter/SingleColumnValueFilter.html#setFilterIfMissing-boolean-
希望有所帮助