Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase, mail # user - HBase filter in scan

Copy link to this message
Re: HBase filter in scan
Andrey Stepachev 2010-12-13, 20:28
Not very easy, but using jRuby and java api, you can.
But it is very depend on how you store you data.
## function converts any value to bytes (using Bytes class methods)
def toBytes(val)
## example analog of the "select * from where key"
def fetch(table, id, args = {})
   key = Writables.getBytes(BsnId.new(id))
   print Bytes.toStringBinary(key); print "\n"
   get table, String.from_java_bytes(key), args
## filters
import "org.apache.hadoop.hbase.filter.QualifierFilter"
import "org.apache.hadoop.hbase.filter.ValueFilter"
import "org.apache.hadoop.hbase.filter.CompareFilter"
import "org.apache.hadoop.hbase.filter.BinaryPrefixComparator"
import "org.apache.hadoop.hbase.filter.SubstringComparator"
def qualifierFilter(prefix)
return QualifierFilter.new(CompareFilter::CompareOp::EQUAL,
def substringFilter(prefix)
return QualifierFilter.new(CompareFilter::CompareOp::EQUAL,
def valueSubstringFilter(prefix)
return ValueFilter.new(CompareFilter::CompareOp::EQUAL,

Later you can combine filters using FilterList.

scan 'bsn.main', { STARTROW=>toBytes(1581791), COLUMNS=>'identifier',
LIMIT=>1, "FILTER" => FilterList.new([qualifierFilter('INN'),

Example above can be written in "pseudo sql"  select <column:qualifiers like
'INN%' and values of columns like '%2009%'> from 'bsn.main' where id 1581791

(of course if you key is really encoded with Bytes.toBytes(long))

Hope this helps.
2010/12/13 Anato1y <[EMAIL PROTECTED]>

> Dear users, please tell me how use hbase shell scan get value by criteria,
> (sql - the equivalent of SELECT name FROM t1 WHERE id = '1 '). Sorry for my
> bad English :)
> --
> View this message in context:
> http://old.nabble.com/HBase-filter-in-scan-tp30445637p30445637.html
> Sent from the HBase User mailing list archive at Nabble.com.