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

醉酒当歌 提交于 2020-01-04 21:36:21

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/31565801/how-to-get-a-column-value-based-on-criteria-like-where-clause-in-hbase-shell

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