How to filter rows with a given column (not null)?

I want to do an hbase check using filters. For example, my table has a family of columns A, B, C, and A has column X. Some rows have column X, and some do not. How can I implement a filter to filter all rows using column X?

+6
source share
3 answers

I think you are looking for SingleColumnValueFilter in HBase. As mentioned in the API

To prevent the entire row from being thrown out if the column is not found in the row, use setFilterIfMissing(boolean) in the Filter object. Otherwise, if a column is found, the entire row will be emitted only if the value passes. If the value fails, the string will be filtered.

But SingleColumnValueFilter wants the value to have the value of the X column "CompareOp" for something, for example, bring this row if ColumnX == "X" or bring this row if ColumnX! = "A sentinel value that ColumnX can never accept "and setFilterIfMissing(true) , so if ColumnX has some value, it is returned.

Hope this pushes you in the right direction.

+9
source

You can use SkipFilter with ColumnPrefixFilter . ColumnPrefixFilter gets the keys in which the column exists (in the HBase row there will only be a column if it matters) the Skip filter will give you “Not” in the first filter, so the row will be omitted

+1
source

Ankit Arnon user1573269

The only way to make it work as below

So - I have a table with columns rule1, rule2, rule3 and so on. Rows can only have a column rule1, or rule1 and rule2, or rule1 and rule2 and rule3 etc. Let's say I want to extract rows that contain ONLY rule1. Now this means that I will have to skip lines that have a rule2.

 Scan getRules = new Scan(); ColumnPrefixFilter rule1Filter = new ColumnPrefixFilter(Bytes.toBytes("rule1")); SingleColumnValueFilter skipRule2Value = new SingleColumnValueFilter(Bytes.toBytes("rules"),Bytes.toBytes("rule2"), CompareOp.EQUAL,Bytes.toBytes("0")); SkipFilter skipRule2 = new SkipFilter(skipRule2Value); getRules.setFilter(rule1Filter); getRules.setFilter(skipRule2); ResultScanner scanner = htable.getScanner(getRules); 

Although this worked, I am not very happy with the solution. It takes time to determine hbase. I would think that there should be a simpler simple method that should not check the value. Arnon, your method does not work, because SkipFilter skips those that DONOT satisfy the condition. Therefore, building it from a ColumnPrefixFilter does not meet the requirements.

0
source

Source: https://habr.com/ru/post/927564/


All Articles