0
votes

I have a column in HBASE table whose each cell contains multiple values (composite value to be more precise) like below:

Sample value in the cell:

'2018-10-15=33|2018-10-16=56'

It is basically a collection of key value pairs with key as date and value as a count. The key value pairs are delimitted by pipe char.

I want to run a scan on this HBASE table (preferably using SingleColumnValueFilter) to find all rows where the cells for the above given column have any particular date say 2018-10-15. Note that the column in question is not a row key.

To give more clarity on my requirement, a similar operation in SQL would look like:

WHERE COLUMN_X LIKE '%2018-10-15%'

How do I set my filter for this scan in HBASE?

I do not find a comparator like the one mentioned below:

org.apache.hadoop.hbase.filter.CompareFilter.CompareOp.LIKE

Please help.

1

1 Answers

2
votes

You can use SubstringComparator with ValueFilter.

i.e.

scan 'yourtable', { COLUMNS => 'cf:COLUMN_X ', FILTER => "ValueFilter(=, 'substring:2018-10-15')"}

If you want to implement it in Java, you can use following :

SubstringComparator comp = new SubstringComparator("2018-10-15");   

SingleColumnValueFilter filter = new SingleColumnValueFilter(
    Bytes.toBytes("cf"),
    Bytes.toBytes("column_X"),
    CompareOp.EQUAL,
    comp
    );
scan.setFilter(filter);

Here you can find more details about how to use comparator and filters : http://hbase.apache.org/0.94/book/client.filter.html