How to apply several QualifierFilter to a row in HBase

≡放荡痞女 提交于 2019-12-05 05:41:35

You can achieve this by defining the following filters:

List<Filter> filters = new ArrayList<Filter>(2);
byte[] colfam = Bytes.toBytes("c");
byte[] fakeValue = Bytes.toBytes("DOESNOTEXIST");
byte[] colA = Bytes.toBytes("col_A");
byte[] colB = Bytes.toBytes("col_B");

SingleColumnValueFilter filter1 = 
    new SingleColumnValueFilter(colfam, colA , CompareOp.NOT_EQUAL, fakeValue);  
filter1.setFilterIfMissing(true);
filters.add(filter1);

SingleColumnValueFilter filter2 = 
    new SingleColumnValueFilter(colfam, colB, CompareOp.NOT_EQUAL, fakeValue);          
filter2.setFilterIfMissing(true);
filters.add(filter2);

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL, filters);
Scan scan = new Scan();
scan.setFilter(filterList);

The idea here is to define one SingleColumnValueFilter per column you are looking for, each with a fake value and a CompareOp.NOT_EQUAL operator. I.e: such a SingleColumnValueFilter will return all columns for a given name.

Source: http://mapredit.blogspot.com/2012/05/using-filters-in-hbase-to-match-two.html

user1246584

I think this line is the issue -

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);

You want it to be -

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);

The filter will try to find a column that has both the column qualifier and there is no such column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!