hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Peterson <kpeter...@biz360.com>
Subject Re: Help using partial-key lookup and compound keys.
Date Wed, 04 Nov 2009 22:51:42 GMT
On Tue, Nov 3, 2009 at 2:13 PM, Artyom Shvedchikov <shoolc@gmail.com> wrote:

> Hallo, folks.
>
> We want to use partial-key lookup and compound keys (search using them)
> with
> Java API.
> Can someone to provide info and example on using such keys and lookups.
>
>
I'm not sure I understand you correctly, but partial key is fine as long as
you are using a prefix.

For example, if your key consists of account:timestamp:event_id, you would
need to make sure that all these values are fixed width -- make account id
an int, not a string, same thing with timestamp. To build your keys do
something like

byte[] row = Bytes.add(Bytes.toBytes(acctId), Bytes.toBytes(time),
Bytes.toBytes(eventId))

Then to get all rows matching a given account and timestamp, do

byte[] startRow = Bytes.add(Bytes.toBytes(acctId), Bytes.toBytes(time));
byte[] endRow = Bytes.add(Bytes.toBytes(acctId), Bytes.toBytes(time + 1));
ResultScanner scanner = table.getScanner(new Scan(startRow, endRow));

If you want to search by something that isn't a prefix of your row key, then
you will need to either user a scanner filter or look into table indexed.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message