简体   繁体   中英

HBase Scan api with multiple filtering conditions

I am very new to HBase api and seeing some strange results when doing the following.

We are trying to scan based on multiple filters. I want to pass all the filter conditions. I am using the below code.

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

I try to look for proper example but none of them seem to be working. Any help in this direction is greatly appreciated. Thanks in advance.

You specified a FilterList where all the filter must pass (like a "AND" behavior). In the list of filter, you have 2 SingleColumnValueFilter which are contradictory : they say that the column COLUMN_FAMILY:COLUMN_NAME must be equal to value1 and value2 at the same time. I think that's why you don't get result with the context of your 1st and 3rd comment.

Concerning your 2nd comment, I think you have to keep in mind that the SingleColumnValueFilter are applied only if the column exists in the Scan. It may be the explanation of what you see. Check the setFilterIfMissing(boolean) method : https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/filter/SingleColumnValueFilter.html#setFilterIfMissing-boolean-

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM