You can use filters (
http://hbase.apache.org/docs/current/api/org/apache/hadoop/hbase/filter/SingleColumnValueFilter.html
)
 if the number of rows is not too big. I tried 1 million rows in my 4 node
cluster and it took about 8 seconds for the full filtering.

Thanks,
Hari

On Tue, Dec 14, 2010 at 1:58 AM, Andrey Stepachev <[email protected]> wrote:

> 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)
>     String.from_java_bytes(Bytes.toBytes(val))
> end
>
>
> ## 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
> end
>
>
> ## 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,
> BinaryPrefixComparator.new(prefix.to_java_bytes))
> end
> def substringFilter(prefix)
> return QualifierFilter.new(CompareFilter::CompareOp::EQUAL,
> SubstringComparator.new(prefix))
> end
> def valueSubstringFilter(prefix)
> return ValueFilter.new(CompareFilter::CompareOp::EQUAL,
> SubstringComparator.new(prefix))
> end
>
> Later you can combine filters using FilterList.
>
> scan 'bsn.main', { STARTROW=>toBytes(1581791), COLUMNS=>'identifier',
> LIMIT=>1, "FILTER" => FilterList.new([qualifierFilter('INN'),
> valueSubstringFilter("2009")])}
>
> 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.
> >
> >
>

Reply via email to