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

Switch to Threaded View
HBase >> mail # user >> Scan not working properly on composite keys

Copy link to this message
Re: Scan not working properly on composite keys

The rows are physically sorted on disk (and in memory) according to the row keys you define, and that's the only way that HBase can access them (unlike a relational database, it doesn't have built in indexes that allow you to access rows by something other than their physical sort order). So having a general wildcard lookup feature wouldn't be practical; in reality, it would have to scan ever row in the table to see which ones match your pattern.

That said, you could build a little wrapper on top of your access code as follows (pseudocode):

function getRowsByUser(string user) {
prefixes = "admin", "viewer", "etc";
for each prefix in prefixes {
result.add(getRowsFromHBase(prefix + user));
return result;

That way, at least your scan is linear in the number of prefixes--it just does one constant-time seek to the start of the rows for the given user, for each of the prefixes you know about.

You can't expect functionality like this to be built in to HBase, because to HBase, row keys are simply byte arrays, nothing more. It does nothing to enforce structure on them, that's entirely your application's job.


On Aug 29, 2011, at 10:49 AM, Stuti Awasthi wrote:

> Hi,
> Sure, I tried also by prefixing with admin, and it was working fine. I was just wondering that is there any way that we can get the information from Hbase using some part of Composite keys or wild card characters ?
> Thanks
> -----Original Message-----
> From: Buttler, David [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 29, 2011 8:46 PM
> Subject: RE: Scan not working properly on composite keys
> The scan started at "viewer/user3" because that is the next key after "user2".  If your keys have a prefix, like admin or viewer, then you need to prepend that to your start row as well.  Hbase has no magic where it can intuit your intent.
> Dave
> -----Original Message-----
> From: Stuti Awasthi [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 29, 2011 12:39 AM
> Subject: Scan not working properly on composite keys
> Hi Friends,
> I have a query regarding scan operation on composite keys.
> I have table as follows :
> admin/user1                                       column=info:email, timestamp=1314594930540, value=abc
> admin/ user1                                    column=info:mobile, timestamp=1314594940686, value=123456
> admin/ user1                                    column=info:name, timestamp=1314594915091, value=def
> admin/user2                                     column=info:email, timestamp=1314597627865, value=def
> admin/ user2                                    column=info:mobile, timestamp=1314597636663, value=67890
> admin/ user2                                    column=info:name, timestamp=1314597614585, value=pqr
> viewer/user3                                     column=info:email, timestamp=1314601194373, value=pqr
> viewer/ user3                                    column=info:mobile, timestamp=1314601256479, value=12345
> viewer/ user3                                   column=info:name, timestamp=1314601207662, value=xyz
> I want to find all the records of "user2". For this I tried following query but it is giving me all records of user3 :
> hbase(main):005:0> scan 'users', {STARTROW=>'user2'}
> ROW                                         COLUMN+CELL
> viewer/user3                          column=info:email, timestamp=1314601194373, [EMAIL PROTECTED]
> viewer/ user3                          column=info:mobile, timestamp=1314601256479, value=37498734893
> viewer/ user3                          column=info:name, timestamp=1314601207662, value=satyendra pandey
> 1 row(s) in 0.0330 seconds
> I also tried various queries for this but not getting correct result. I am definitely missing something. Please help
> Thanks & Regards
> Stuti Awasthi
> Sr Specialist
> ________________________________
> ----