Vivek Hansraj
Vivek Hansraj

Reputation: 21

How to get a column value based on criteria like where clause in Hbase shell

I am new to Hbase.

I have a scenario where I need to pull a filename based on the status and current date.

So I have created 3 columns; filename, status and date in the Hbase table.

How can I get the filename based on the condition that the status=true and date is today?

This query needs to be executed on the Hbase shell.

Upvotes: 2

Views: 2206

Answers (1)

Shyam
Shyam

Reputation: 526

Achieving this in a concise way is difficult. But here is what I did. hbase shell is a JRuby shell, which enables us to do the following example.

import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.filter.SubstringComparator
import org.apache.hadoop.hbase.filter.FilterList

filter1 = SingleColumnValueFilter.new(Bytes.toBytes('cf'), Bytes.toBytes('qualifier'), CompareFilter::CompareOp.valueOf('EQUAL'), SubstringComparator.new('valueToSearch'));
filter2 = SingleColumnValueFilter.new(Bytes.toBytes('cf'), Bytes.toBytes('qualifier2'), CompareFilter::CompareOp.valueOf('EQUAL'), SubstringComparator.new('valueToSearch2'));

filterList = FilterList.new([filter1, filter2]);

scan 'table', {FILTER =>  filterList}

You could import any other Filters, Comparator, Java objects etc

I have used SubstringComparator for testing.
In your case it should be BinaryComparator (Probably better performance wise as well).

Refer this question if you want to read more about a similar hack.

Hope it helps.

Upvotes: 2

Related Questions