2

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.

choroba
  • 231,213
  • 25
  • 204
  • 289
  • Have a look at the answers of the following questions. http://stackoverflow.com/questions/12634321/doing-a-valuefilter-or-a-columnfilter-on-hbase-shell http://stackoverflow.com/questions/11013197/scan-htable-rows-for-specific-column-value-using-hbase-shell – Shyam Jul 22 '15 at 23:22
  • Thanks ,I have gone through the links .But I haven't got the solution yet. just to rephrase my question, say i have 3 coiumns in my table. i need to get the first column corresponding to a condition which is applied on 2nd column and 3rd columns. The sql equivalent of this would be select first column from table where (2nd column =x and 3rd column=y). i need this implemented in the hbase shell. – Vivek Hansraj Jul 23 '15 at 06:15
  • My bad, misread the question. I'll give it a shot at the problem. – Shyam Jul 23 '15 at 06:55

1 Answers1

2

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.

Community
  • 1
  • 1
Shyam
  • 516
  • 3
  • 7