Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 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
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.
>
>
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB